Step through cells in a selected range

C

CLR

Hi All.......

I can step through the cells in a column ok, but need help now in stepping
through all the cells in a selected RANGE, (say C3:e7), and perform a task
against each cell.

Any help would be much appreciated.

Vaya con Dios,
Chuck, CABGx3
 
E

Ed from AZ

Sub XX_CellsInRng()

Dim rng As Range
Dim cll As Range

Set rng = Selection
For Each cll In rng
Debug.Print cll.Value
Next cll

End Sub


Cheers!
Ed
 
C

CLR

Hi Ed...........
This works great, much thanks...... but one more favor if you please........

Sub XX_CellsInRng()
Dim rng As Range
Dim cll As Range
Set rng = Selection
For Each cll In rng
If cll.Value < 1000 And cll.Value <> "" Then
cll.Value = 1001
End If
Next cll
End Sub

How can I specifically exclude a cell containing TEXT from the cll.value test?

Vaya con Dios,
Chuck, CABGx3
 
H

Hemant_india

hi
see if this works
Sub XX_CellsInRng()
Dim rng As Range
Dim cll As Range
Set rng = Selection
For Each cll In rng
if not istext(cll.text) then
If cll.Value < 1000 And cll.Value <> "" Then
cll.Value = 1001
End If
end if
Next cll
End Sub
 
C

CLR

Hi Hemant_india.....

Your code didn't work directly for me, (I forgot to mention I'm using XL97),
but this slight modification of it did work fine..........

Sub XX_CellsInRng()
Dim rng As Range
Dim cll As Range
Set rng = Selection
For Each cll In rng
If IsNumeric(cll.Value) Then
If cll.Value < 1000 And cll.Value <> "" Then
cll.Value = 1001
End If
End If
Next cll
End Sub

Thanks very much for heading me in the right direction.

Vaya con Dios,
Chuck, CABGx3
 
C

CLR

Hi Hemant_india.....

Your code didn't work directly for me, (I forgot to mention I'm using XL97),
but this slight modification of it did work fine..........

Sub XX_CellsInRng()
Dim rng As Range
Dim cll As Range
Set rng = Selection
For Each cll In rng
If IsNumeric(cll.Value) Then
If cll.Value < 1000 And cll.Value <> "" Then
cll.Value = 1001
End If
End If
Next cll
End Sub

Thanks very much for heading me in the right direction.

Vaya con Dios,
Chuck, CABGx3
 
C

CLR

Hi Hemant_india.....

Your code didn't work directly for me, (I forgot to mention I'm using XL97),
but this slight modification of it did work fine..........

Sub XX_CellsInRng()
Dim rng As Range
Dim cll As Range
Set rng = Selection
For Each cll In rng
If IsNumeric(cll.Value) Then
If cll.Value < 1000 And cll.Value <> "" Then
cll.Value = 1001
End If
End If
Next cll
End Sub

Thanks very much for heading me in the right direction.

Vaya con Dios,
Chuck, CABGx3
 
C

CLR

As you can see..........I'm having a little trouble with the Newsgroup
interface....sorry for the multiple posts, but three "thank you's" is better
than none.

Vaya con Dios,
Chuck, CABGx3
 

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

Top