looping through each cell in a worksheet or range

  • Thread starter Thread starter tracey
  • Start date Start date
T

tracey

I am looking for an example of code that I can use to
check the contents of each cell on a worksheet or in a
range of cells for variable conditions. I think I know
how to code the variables, however I am stuck on
the "looping" from cell to cell. I am importing data from
another application and I need to clean up some data,
however the field counts and record counts change every
time.

Thanks!!!!!!!!!!!!!!!!!!!!!!!!!
 
tracey said:
I am looking for an example of code that I can use to
check the contents of each cell on a worksheet or in a
range of cells for variable conditions.

If you select one or more cells, it's like this:

Sub LoopCells()
Dim All As Range, Cel As Range
Set All = Intersect(Selection, ActiveSheet.UsedRange)
For Each Cel In All.Cells
'whatever with Cel.Value
Next
End Sub

edit to
Set All = ActiveSheet.UsedRange
for the whole sheet, no selecting.
Thanks!!!!!!!!!!!!!!!!!!!!!!!!!

You're welcome !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Best wishes Harald
 
Generic Example

Dim cell as Rang
For Each cell in Range("A1:A1000"
If Len(cell.Value) < 2 Then cell.Interior.Color = RGB(255,0,0
Nex

-Brad
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top