-
I am having a problem with a macro i have to write. I am trying to walk through lets say cells F1-F10. I must check each cell's value in this range and if it is greater than one i must do something. I am not sure however how to walk through the cell's value. Any help would be greatly appriciated.
Steve Warker
-
You're working with excel, right?
OK, the simplest trick (without presenting code) is to record the macro in Excel and then edit the macro to look what has been written.
A simple way to learn some excel-basic.
I've made a small program that also checks values in cells, but it's to long ago to remember, sorry.
You probably need the .cells property (maybe:
Cells(A1, C1).Value = "2" )
Just try to let the macro recorder do your job...
good luck !
Fedor
(don't hesitate to ask more questions)
-
Code:
Dim rng As Range, rng1 As Range, rng2 As Range, cell As Range
' get contiguous range of cells below start cell
Set rng1 = .Range("F1")
Set rng2 = rng.End(xlDown)
Set rng = Range(rng1, rng2)
' excel VBA is a RAM pig
' as a general rule, always free what you can.
Set rng1 = Nothing
Set rng2 = Nothing
' you could skip the above and simply use
' Set rng = .Range("F1:F10")
' but thought it might give you a few ideas...
' Irerate range
For Each cell In rng
Msgbox "Value of cell " & cell.address & " is " & cell.value
Next cell
Set rng = nothing
Set cell = nothing