Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default How to use a Range in a Loop

I was wondering how you can use a range for a loop start and end positions.

Give a range B3:B25

I wouldlike to loop through each cell and if there exists a value (any
number including zero) then replace the value with the associated formula ...
in this case if B3, B17 and B23 were numbers then

B3 becomes =sum(C3:H3)
B17 becomes =sum(C17:H17)
B23 becomes =sum(C23:H23)

Also can variables be used as cell references

dfrank = C17
B17 becomes =sum(dfrank:H17)

thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to use a Range in a Loop

Dim cell as Range
for each cell in Range("B3:B25")
if not isempty(cell) then
if isnumeric(cell) then
cell.Formula = "=SUM(C" & cell.row & ":H" & cell.row & ")"
end if
end if
Next

You can certainly use a variable

Dim sStart as String, sStop as String
Dim cell as Range
sStart = "C"
sStop = "H"
for each cell in Range("B3:B25")
if not isempty(cell) then
if isnumeric(cell) then
cell.Formula = "=SUM(" & sStart & cell.row & ":" & sStop & cell.row &
")"
end if
end if
Next

--
Regards,
Tom Ogilvy


"Glen" wrote in message
...
I was wondering how you can use a range for a loop start and end positions.

Give a range B3:B25

I wouldlike to loop through each cell and if there exists a value (any
number including zero) then replace the value with the associated formula
...
in this case if B3, B17 and B23 were numbers then

B3 becomes =sum(C3:H3)
B17 becomes =sum(C17:H17)
B23 becomes =sum(C23:H23)

Also can variables be used as cell references

dfrank = C17
B17 becomes =sum(dfrank:H17)

thanks




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default How to use a Range in a Loop



"Tom Ogilvy" wrote:

Dim cell as Range
for each cell in Range("B3:B25")
if not isempty(cell) then
if isnumeric(cell) then
cell.Formula = "=SUM(C" & cell.row & ":H" & cell.row & ")"
end if
end if
Next

You can certainly use a variable

Dim sStart as String, sStop as String
Dim cell as Range
sStart = "C"
sStop = "H"
for each cell in Range("B3:B25")
if not isempty(cell) then
if isnumeric(cell) then
cell.Formula = "=SUM(" & sStart & cell.row & ":" & sStop & cell.row &
")"
end if
end if
Next

--
Regards,
Tom Ogilvy


"Glen" wrote in message
...
I was wondering how you can use a range for a loop start and end positions.

Give a range B3:B25

I wouldlike to loop through each cell and if there exists a value (any
number including zero) then replace the value with the associated formula
...
in this case if B3, B17 and B23 were numbers then

B3 becomes =sum(C3:H3)
B17 becomes =sum(C17:H17)
B23 becomes =sum(C23:H23)

Also can variables be used as cell references

dfrank = C17
B17 becomes =sum(dfrank:H17)

thanks





Tom,

Thanks for the help... this should get me started quite nicely.

regards,
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
Range Loop lbargers Excel Programming 2 March 28th 06 04:15 PM
Add a Range to an existing Range in a loop? Mick Excel Programming 3 June 18th 05 06:12 AM
Loop through a range James Excel Programming 1 April 8th 05 07:59 PM
loop in range Aksel Børve Excel Programming 3 March 9th 05 02:30 PM
Loop in a Range aksel børve Excel Programming 2 March 8th 05 06:40 PM


All times are GMT +1. The time now is 03:26 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"