Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default syntax for relative cell change and looping

you can go into the VBE (alt+F11) and click on the help button in the menu.

looping is done with a For each construct

Sub Tester1()
dim rng as Range
dim cell as Range
for each cell in Range("A1:A100")
if cell.offset(0,1).Value = "x" then
if rng is nothing then
set rng = cell
else
set rng = union(rng,cell)
end if
Next cell
if not rng is nothing then
rng.copy Destination:=worksheets("sheet3").Range("A1")
End if
End Sub

or a Do ... Loop construct

There is also a While . . . Wend, but usually people use Do ... Loop as it
is more flexible.

If you don't have a collection like above, you can also use a for each with
a counter

for i = 1 to 100

Next i

--
Regards,
Tom Ogilvy


BwanaP wrote in message
m...
I did some macros years ago mostly by recording, but I remember some
of the code looking different. I have a list of maybe 30 items in a
column, the next column is used to select those items. I want to check
if an item is selected and if so copy it to another part of the sheet
(which would be the defined print range). I know this should be very
easy, but can't remember how to loop (and how to end it) and increment
a relative cell change.

If there is somewhere I can find a listing of commands online that
would be helpful. I live overseas so can't just go out and buy a book
on this.



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
Change a cell reference from relative to absolute Fred Holmes Excel Discussion (Misc queries) 2 June 4th 09 02:03 AM
Syntax for a relative formula Ian Murphy Excel Worksheet Functions 2 September 8th 06 05:32 PM
How do I change a macro to use relative cell addresses? Roger D Excel Discussion (Misc queries) 2 July 30th 05 07:35 PM
How do I change a Macro to use relative cell addresses? Roger D Excel Discussion (Misc queries) 1 July 30th 05 07:00 PM
How do I change a cell from absolute reference to relative referen simonsez Excel Discussion (Misc queries) 1 May 17th 05 08:39 PM


All times are GMT +1. The time now is 04:22 AM.

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

About Us

"It's about Microsoft Excel"