If Statement Kills the Do Loop

mmccall

New Member
Joined
Jan 21, 2016
Messages
5
I am trying to loop through data with the same if statement but once the if statement is fulfilled the first time the loop no longer calls the if statement for some reason, can someone please help?

here is my code:

*Row = 6 at this point

Do Until Row = 36

If ActiveSheet.Cells(Row, Col).Value2 = "V" Then
Sheets("Vacation").Select
ActiveSheet.Cells(Row, 3).Select
ActiveCell = ActiveSheet.Cells(Row, 3).Value2 + 1
ActiveCell.End(xlToRight).Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = today
End If
Row = Row + 1

Loop
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
2 thoughts:

1) Your problem is probably because if the IF is executed, you select the Vacation sheet and never select your original sheet again. You may want to change the IF to something like:

If Sheets("Sheet1").Cells(Row, Col).Value2 = "V" Then

2) The word "Row" is a bad choice for a variable, since it is a reserved word to VBA. You can cause some very hard-to-find errors doing that. That's why you see a lot of "MyRow" and "MyCol" variables in code.

Hope this helps!
 
Last edited:
Upvote 0
2 thoughts:

1) Your problem is probably because if the IF is executed, you select the Vacation sheet and never select your original sheet again. You may want to change the IF to something like:

If Sheets("Sheet1").Cells(Row, Col).Value2 = "V" Then

2) The word "Row" is a bad choice for a variable, since it is a reserved word to VBA. You can cause some very hard-to-find errors doing that. That's why you see a lot of "MyRow" and "MyCol" variables in code.

Hope this helps!

Problem 1 fixed it, thank you so much I knew I was over thinking it!
 
Upvote 0

Forum statistics

Threads
1,216,136
Messages
6,129,084
Members
449,485
Latest member
greggy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top