Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.links
|
|||
|
|||
INserting Specific Number of Rows via macro
Hi,
I am new to writing macros...I have a few books but I can't seem to figure this on out. So, I have the following data: Date Fuel Price 7/1/06 $5.65 7/2/06 $7.00 7/3/06 $6.32 Basically, I need to insert 23 rows under each date (so that i have a total of 24 rows for each date). Then, I'd like to copy the contents of the cells above the insertion so that i have a fuel price for every hour of each date. Does that make sense? I thought this would be easy...and now I've wasted so much time, I could have done it manually a million times now! Thanks! |
#2
Posted to microsoft.public.excel.links
|
|||
|
|||
INserting Specific Number of Rows via macro
Hello,
As you're getting started, try recording what you're doing in a macro and then you can see how excel does it. It might not be efficient code, but it will point you in the right direction. For this example I recorded inserting 2 or 3 rows at a time to get this, Range("A2:A3").Select Selection.EntireRow.Insert This inserts new rows in rows 2 and 3 and pushes the old ones to 4 and 5. To use this for your problem, try either using a small FOR loop to insert 23 rows or select a range that includes 23 rows and insert once. Here's the FOR loop, Dim Rng As Range Dim i As Integer Set Rng = Range("A2") For i = 1 To 23 Rng.EntireRow.Insert Next Hope that helps, Dsambo wrote: Hi, I am new to writing macros...I have a few books but I can't seem to figure this on out. So, I have the following data: Date Fuel Price 7/1/06 $5.65 7/2/06 $7.00 7/3/06 $6.32 Basically, I need to insert 23 rows under each date (so that i have a total of 24 rows for each date). Then, I'd like to copy the contents of the cells above the insertion so that i have a fuel price for every hour of each date. Does that make sense? I thought this would be easy...and now I've wasted so much time, I could have done it manually a million times now! Thanks! |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
macro to repeat a formula a set number of rows apart | Excel Discussion (Misc queries) | |||
formula to use when number of rows changes dynamically | Excel Worksheet Functions | |||
Formula for current month minus one = Quarter number in a macro. | Excel Discussion (Misc queries) | |||
inserting rows through external data source | Excel Discussion (Misc queries) | |||
flexible paste rows function that inserts the right number of rows | Excel Discussion (Misc queries) |