Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 142
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,117
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone know of program or Excel VBA to examine set of numbers for Sum match? [email protected] Excel Discussion (Misc queries) 2 August 27th 08 05:13 AM
Help adjusting code to examine whole account groups first edluver Excel Programming 1 March 28th 07 04:13 AM
Increment/Increment letter in alphabetical order Neil Goldwasser Excel Programming 3 January 25th 06 09:07 AM
examine print queue from vb Mike Molyneaux Excel Programming 2 December 3rd 03 03:38 PM
Leave last col alone David Turner Excel Programming 0 September 1st 03 07:21 PM


All times are GMT +1. The time now is 09:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"