Some strange things are happening to me in VBA. Somedays I am coding and everything works fine, then I go out of the code and the next day when I want to run the exact same code from the day before the code doesn't go into the loop, but jumps directly into end sub().
I tried to use the Activate sheet function, it seemed to work for 10 seconds and then afterwards suddenly it didn't work again which means my code didn't go into the loop again. The reason why I was using Activate sheet function was because I was afraid that my code was pointing at the wrong excel file / sheet. I have a lot of excel files and all of the sheets in those excel files are called Sheet1 could that create problems??
To give you a concrecte example, say I day one use the following code to loop through a column:
Sub stuff()
' Sheet1.Activate
lngLastRow = Worksheets("Sheet1").Range("A" & Rows.Count).End(xlUp).Row
Set sheet1ArkRng = Worksheets("Sheet1").Range("A1:Z" & lngLastRow)
Set offsheetarkrng = Worksheets("Sheet1").Range("L5")
Dim i As Integer
For i = 3 To sheet1ArkRng.Rows.Count
sheet1VirkNavn = sheet1ArkRng.Cells(RowIndex:=i, ColumnIndex:="C").Value
Next i
End Sub
Then day 1 everything works fine and the variable sheet1VirkNavn shows me the value of the rows in column C. It can be seen when I debug.
Then day 2 once I debug the exact same code from the exact same file it goes to
"For i = 3 To sheet1ArkRng.Rows.Count"
and then jumps directly into
End sub
Worksheets("Sheet1")will just look at whatever book is currently active. - Darren Bartrup-CookFor i = 3 to 1). - Darren Bartrup-CookSheet1of the ActiveWorkbook - maybe not what you expect. - FunThomas