#1   Report Post  
Posted to microsoft.public.excel.misc
Kate
 
Posts: n/a
Default For next loops

Hi,
I want to format an excel sheet using a macro. This involves inserting
new rows etc, but the number of rows to insert depends on the number of
entries that are in the original form. Each entry is given a
consecutive number. Currently, the code is as follows:

Range("3:3,5:5,7:7,9:9,11:11,13:13,15:15").Select
Range("A15").Activate
Selection.Insert Shift:=xlDown

Instead of using numbers (since these will change), I want to do
something like:

for j=3 to 3+2*(max(B2:B200)-2) step 2
Range("j:j").Select
Selection.Insert Shift:=xlDown
next j
end

This doesn't work. It doesn't like Range("j:j").Select. I have tried
declaring j as various things but still no luck. I'm sure this must be
something very simple. Can anyone help?

Thanks

  #3   Report Post  
Posted to microsoft.public.excel.misc
Kate
 
Posts: n/a
Default For next loops

Fantastic! I used:

For i = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
Rows(i).Insert
Rows(i).Insert

Thanks alot!

  #4   Report Post  
Posted to microsoft.public.excel.misc
Kate
 
Posts: n/a
Default For next loops


Using that theory, how do you select actual cells?

For i = Cells(Rows.Count, "a").End(xlUp).Row To 12 Step -3
Range("Ci:Oi").Select
with selection
..mergecells = true
end with
next

clearly you can't go Ci:Oi, so what would you use?

  #5   Report Post  
Posted to microsoft.public.excel.misc
Dana DeLouis
 
Posts: n/a
Default For next loops

If the # of rows to insert were a variable, another option might be:

Dim R As Long
For R = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
Rows(R).Resize(2).Insert
Next R

--
HTH. :)
Dana DeLouis
Windows XP, Office 2003


"Kate" wrote in message
ups.com...
Fantastic! I used:

For i = Cells(Rows.Count, "a").End(xlUp).Row To 3 Step -1
Rows(i).Insert
Rows(i).Insert

Thanks alot!





  #6   Report Post  
Posted to microsoft.public.excel.misc
Don Guillett
 
Posts: n/a
Default For next loops

not quite sure what you want here but

For i = Cells(Rows.Count, "a").End(xlUp).Row To 12 Step -3
range(cells(i,"c"),cells(i,"o")).mergecells=true
next


--
Don Guillett
SalesAid Software

"Kate" wrote in message
oups.com...

Using that theory, how do you select actual cells?

For i = Cells(Rows.Count, "a").End(xlUp).Row To 12 Step -3
Range("Ci:Oi").Select
with selection
.mergecells = true
end with
next

clearly you can't go Ci:Oi, so what would you use?



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
How to Chart the Maximum Point within Two Loops Faye Charts and Charting in Excel 3 May 11th 06 08:00 PM
Edit this macro code to loop and end GarToms Excel Discussion (Misc queries) 1 January 27th 06 12:50 PM
Do loops grandfilth Excel Discussion (Misc queries) 1 November 10th 05 12:00 AM
Max limit of 7 nested loops Subu Excel Worksheet Functions 2 May 28th 05 02:14 PM


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