how does vba know to do nothing

kylefoley76

Well-known Member
Joined
Mar 1, 2010
Messages
1,553
i got this code from mrexcel live lessons ch 31. in it there is a line that says

Code:
if this dept = lastdept then
' do nothing

well, how does vba know to do nothing? there is no command after the "then" statement. here is a screen shot of the full code

Picture6-6.png
 
Because there is no command after the "then" statement, excel will literally do nothing. The commented part 'do nothing' is just FYI.
 
Upvote 0
That structure however is strange instead of Then Do Nothing, change the condition to

If ThisDept <> LastDept Then
LastRow = i - 1
'etc
End If


and drop the Else
 
Upvote 0
HOTPEPPER

I can kind of see what you mean but I think having a comment like that, if in the right place, can actually help.

Mind you I suppose it could be a little confusing if overused.:)
 
Upvote 0
I think it's just adding lines of code. If you're not going to use Then, then just change it to a condition that doesn't require Else.

It would be the same situation if you didn't need an Else but included it to say do nothing.
 
Upvote 0

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