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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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,216,079
Messages
6,128,687
Members
449,464
Latest member
againofsoul

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