dellehurley
Board Regular
- Joined
- Sep 26, 2009
- Messages
- 171
- Office Version
- 365
- Platform
- Windows
HI
I am Google and Youtube trained when it comes to VBA so my basics can be a little lacking, so my apologise in advance.
I am writing a troubleshooting procedure for a database and I have a couple of questions about For Next To loops when if comes to best practice as well as if there are issues I have not foreseen with reusing the same terms. See the code below...
\
Many Thanks for the clarification and help.
Dannielle
I am Google and Youtube trained when it comes to VBA so my basics can be a little lacking, so my apologise in advance.
I am writing a troubleshooting procedure for a database and I have a couple of questions about For Next To loops when if comes to best practice as well as if there are issues I have not foreseen with reusing the same terms. See the code below...
VBA Code:
For i = 2 To lastrow 'does the j need to be changed up for each loop (to the k for eg.) or
For j = 1 To 3 'only if they use the same range or
'Do something or I can keep using the j as the loop ends between uses
Next j
For k = 4 To 6
'do something
Next k
Next i
For i = 2 To lastrow 'or if totally separate this this do the i and j need to be changed
For j = 1 To 3 'each time or fine to continue forever.
'Do something
Next j
Next i
'If name a variable(?) like this within a loop like the top one with i loop containing many sub loops
'does this need to declared for each loop or only the once?
For i = 2 To lastrow
For j = 2 To 10
FileName = ThisWorkbook.Sheets("Sheet1").Cells(i, j).Value
Next j
For j = 2 To 10
FileName = ThisWorkbook.Sheets("Sheet1").Cells(i, j).Value
Next j
Next i
End Sub
Many Thanks for the clarification and help.
Dannielle