Strange Excel VBA error "Too complex expression" -1. # IND

I have very simple and simple VBA code in an event Worksheet_SelectionChange, for example:

btnB.Top = btnA.Top + btnA.Height

It works fine on my computer, but it works sporadically on my colleague's computer. It seems that 3 out of 5 clicks around the sheet will produce an error "Expression Too Complex". The other 2 work without error. I tried:

Dim D as Double:D = btnA.Top + btnA.Height
btnB.Top = D

And the same thing, sometimes it works, sometimes it gives an error. When an error occurred, I broke and checked the value Dthat was "-1.#IND". I searched for this value and found that it means that it is interdependent. btnA.Topis around 11,500, so this is not an overflow problem. There seems to be no rhyme or reason for this problem. In 16 years of programming VB and VBA, I have never seen or heard anything like it. Thanks for any help / understanding.

Change full code:

Sub LineUpBtns()
    CommandButton2.Top = CommandButton1.Top + CommandButton1.Height
    CommandButton3.Top = CommandButton2.Top + CommandButton2.Height
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    LineUpBtns
End Sub
+5
source share
3 answers

, , , , , ... , - , , , ...

Sub LineUpBtns()        
   Sheets("Sheet1").Shapes("CommandButton2").Top = Sheets("Sheet1").Shapes("CommandButton1").Top + Sheets("Sheet1").Shapes("CommandButton1").Height 
   Sheets("Sheet1").Shapes("CommandButton3").Top = Sheets("Sheet1").Shapes("CommandButton2").Top + Sheets("Sheet1").Shapes("CommandButton2").Height 
End Sub  

, !

+1

#IND - NaN ( ), , undefined/ . -1. # IND ().

, , - :

Dim d As Double

On Error Resume Next
d = 0 / 0
On Error GoTo 0

, , . - . , , , , www.ozgrid.com/forum, .

0

Try adding this to your code.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    application.EnableEvents = False
    ''''your code here
    application.EnableEvents = True
End Sub

This will not lead to overflow, then

0
source

All Articles