Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
Hi,
I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano, |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
On May 1, 12:21 pm, Ivano wrote:
Hi, I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano, This should work. Rob Sub test() Dim myCell As Range, rng As Range Set rng = Range("A1:A10") For Each myCell In rng If Abs(myCell) 5 Then myCell = myCell + 1 Next End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
Try this...
Sub IncrementStuff() Dim rngToIncrement As Range Dim rng As Range Set rngToIncrement = Sheets("Sheet1").Range("a1:a10") For Each rng In rngToIncrement If rng.Value 5 Then rng.Value = rng.Value + 1 Next rng End Sub -- HTH... Jim Thomlinson "Ivano" wrote: Hi, I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano, |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
increment each cell within that range?
or increment the total? i believe you mean each cell something like this would work (not tested) sub ivano() dim c as range dim myrange as range dim ivalue as integer dim ws as worksheet set ws = activesheet set myrange = ws.range("a1:a10") for each c in myrange ivalue = c 'this might need to be c.value if ivalue <= "5" then 'do nothing else ivalue = ivalue+1 end if next c end sub hope it helps! susan On May 1, 1:21 pm, Ivano wrote: Hi, I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano, |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
whoops
if ivalue <= "5" then 'do nothing should be if ivalue="5" then but everybody else's suggestions did the same basic thing, but were much more concise. :D susan On May 1, 1:37 pm, Susan wrote: increment each cell within that range? or increment the total? i believe you mean each cell something like this would work (not tested) sub ivano() dim c as range dim myrange as range dim ivalue as integer dim ws as worksheet set ws = activesheet set myrange = ws.range("a1:a10") for each c in myrange ivalue = c 'this might need to be c.value if ivalue <= "5" then 'do nothing else ivalue = ivalue+1 end if next c end sub hope it helps! susan On May 1, 1:21 pm, Ivano wrote: Hi, I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano,- Hide quoted text - - Show quoted text - |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
examine value, leave it or increment it
Sub increment()
Dim r As Range Dim myRange As Range Set myRange = ActiveSheet.Range("A1:A10") For Each r In myRange If r.Value 5 Then r.Value = r.Value + 1 Next End Sub Gord Dibben MS Excel MVP On Tue, 1 May 2007 10:21:03 -0700, Ivano wrote: Hi, I want a macro that will examin cells within range A1 to A10 and if it is equal to or less then 5 leave it alone else increment it by one. Thanks Ivano, |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Anyone know of program or Excel VBA to examine set of numbers for Sum match? | Excel Discussion (Misc queries) | |||
Help adjusting code to examine whole account groups first | Excel Programming | |||
Increment/Increment letter in alphabetical order | Excel Programming | |||
examine print queue from vb | Excel Programming | |||
Leave last col alone | Excel Programming |