Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default macro to insert rows & copy cells

I need to create rows of data based on days of the week. I start with a
calendar date and delete rows for days of the week where there are no
records. I need to now insert rows based on the remaining days of the week.

Specifically, on Wednesdays, I need to insert 1 row and copy cells from the
row above. On Thursdays and Fridays, I need to insert 3 rows and copy the
respective cells from each day. On Saturdays, I need to insert 4 rows and
copy the cells for Saturday.

This needs to go through the entire data set for one month or two months.
Any ideas?

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default macro to insert rows & copy cells

Hi,

Try this which determines day of week from date and inserts/copies
accordingly

HTH

Sub InsertandCopy()

Dim ws1 As Worksheet
Dim r As Long, Lastrow As Long

' Number of inserts for Sunday to Saturday ....
nInserts = Array(0, 0, 0, 1, 3, 3, 4, 0)

Set ws1 = Worksheets("Sheet1")

With ws1

Lastrow = .Cells(Rows.Count, 1).End(xlUp).Row

For r = Lastrow To 2 Step -1
n = nInserts(Weekday(Cells(r, 1)) - 1)
If n < 0 Then
.Rows(r + 1).Resize(n).Insert Shift:=xlDown
.Rows(r).Copy .Rows(r + 1).Resize(n)
End If
Next r

End With

End Sub


"D Hafer - TFE" wrote:

I need to create rows of data based on days of the week. I start with a
calendar date and delete rows for days of the week where there are no
records. I need to now insert rows based on the remaining days of the week.

Specifically, on Wednesdays, I need to insert 1 row and copy cells from the
row above. On Thursdays and Fridays, I need to insert 3 rows and copy the
respective cells from each day. On Saturdays, I need to insert 4 rows and
copy the cells for Saturday.

This needs to go through the entire data set for one month or two months.
Any ideas?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default macro to insert rows & copy cells

Thank you! That worked perfectly!


"Toppers" wrote:

Hi,

Try this which determines day of week from date and inserts/copies
accordingly

HTH

Sub InsertandCopy()

Dim ws1 As Worksheet
Dim r As Long, Lastrow As Long

' Number of inserts for Sunday to Saturday ....
nInserts = Array(0, 0, 0, 1, 3, 3, 4, 0)

Set ws1 = Worksheets("Sheet1")

With ws1

Lastrow = .Cells(Rows.Count, 1).End(xlUp).Row

For r = Lastrow To 2 Step -1
n = nInserts(Weekday(Cells(r, 1)) - 1)
If n < 0 Then
.Rows(r + 1).Resize(n).Insert Shift:=xlDown
.Rows(r).Copy .Rows(r + 1).Resize(n)
End If
Next r

End With

End Sub


"D Hafer - TFE" wrote:

I need to create rows of data based on days of the week. I start with a
calendar date and delete rows for days of the week where there are no
records. I need to now insert rows based on the remaining days of the week.

Specifically, on Wednesdays, I need to insert 1 row and copy cells from the
row above. On Thursdays and Fridays, I need to insert 3 rows and copy the
respective cells from each day. On Saturdays, I need to insert 4 rows and
copy the cells for Saturday.

This needs to go through the entire data set for one month or two months.
Any ideas?

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
Need Macro- Insert rows based on dates and copy info from that row Katerinia Excel Discussion (Misc queries) 1 April 6th 10 08:02 PM
Macro to copy previous row and insert two blank rows dd Excel Discussion (Misc queries) 1 April 30th 07 11:25 PM
Macro that will Cut rows and then insert-copy or append rod Excel Discussion (Misc queries) 3 October 21st 06 04:50 PM
macro to insert row, copy cells and keep hidden columns steven_thomas Excel Programming 0 September 26th 05 09:40 PM
Activate a macro to insert a row and copy the formuals from the rows above to the blank row oil_driller Excel Discussion (Misc queries) 1 February 11th 05 03:30 PM


All times are GMT +1. The time now is 03:29 AM.

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"