vba looping if then else structure

asdfasdf

New Member
Joined
Aug 19, 2009
Messages
9
I'm doing a 'if then else' structure on vba - where i want the if then else function to work on every square - but i can't work out how to make it loop.

so at the moment I want to know if each cell says depreciation and my code is:


ActiveSheet.Cells(2, 1).Select
If ActiveCell = "depreciation" Then
ActiveCell.Interior.Color = vbBlue
Else
MsgBox "error in this cell"
End If
ActiveCell.Offset(1, 0).Select
End Sub

it all works fine except after the next cell is selected the if function doesn't work. Any ideas on how I need to loop this?

Thanks!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Do you even need code, never mind a loop, for this?

It looks to me as though you could at least do the colouring part with straightforward conditional formatting.:)
 
Upvote 0
thanks that helps heaps.
I do need a loop and vba because my actual data set is more complicated and about 5000 cells in length and need to check for words every certain number of cells.
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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