Macro to insert a row after 6 rows and 45 rows
Closed
gamedanny
Posts
4
Registration date
Sunday June 23, 2013
Status
Member
Last seen
June 28, 2013
-
Jun 23, 2013 at 06:37 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 29, 2013 at 09:22 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Jun 29, 2013 at 09:22 AM
Related:
- Macro to insert a row after 6 rows and 45 rows
- Saints row 2 cheats - Guide
- How to delete a row in a table in word - Guide
- Rj 45 colour code - Guide
- How to insert a checkmark in word - Guide
- How to insert photo in word for resume - Guide
5 responses
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 24, 2013 at 01:38 AM
Jun 24, 2013 at 01:38 AM
sample trivial data sheet1
enter A1 1
a2 2
highlight A1:a2 and drag down upto about 108 rows (more ok)
it will 1,2,3,4,5, etc
copy sheet1 data in sheet 2 also lfrom A1 of that sheet
now run this macro and see and ifnecessary modify
enter A1 1
a2 2
highlight A1:a2 and drag down upto about 108 rows (more ok)
it will 1,2,3,4,5, etc
copy sheet1 data in sheet 2 also lfrom A1 of that sheet
now run this macro and see and ifnecessary modify
Sub test() Dim j As Long, k As Long, r As Range, m As Long Worksheets("sheet1").Cells.Clear Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("A1") Worksheets("sheet1").Activate m = 0 j = Cells(Rows.Count, "A").End(xlUp).Row 'MsgBox j Set r = Range("A1") k = Int(j / 51) Do r.Offset(6, 1).EntireRow.Insert Set r = r.Offset(m * 7, 1) r.Offset(45, 1).EntireRow.Insert Set r = Cells(Rows.Count, "A").End(xlUp).End(xlUp) m = m + 1 If m > k Then Exit Do Loop MsgBox "macro over" End Sub
gamedanny
Posts
4
Registration date
Sunday June 23, 2013
Status
Member
Last seen
June 28, 2013
Jun 24, 2013 at 04:45 AM
Jun 24, 2013 at 04:45 AM
Thanks venkat1926 this macro is very close to what I want so thank you!
It adds a blank row after 6, which is great but then the next blank row is inserted after 38. It then inserts one after 6 again, I end up getting a pattern like this: 6, 38, 6, 45, 6, 52, 6, 59, etc. The pattern I need is 6, 45, 45, 45, 45, etc.
This macro is on the way to that so thank you once again!
Danny
It adds a blank row after 6, which is great but then the next blank row is inserted after 38. It then inserts one after 6 again, I end up getting a pattern like this: 6, 38, 6, 45, 6, 52, 6, 59, etc. The pattern I need is 6, 45, 45, 45, 45, etc.
This macro is on the way to that so thank you once again!
Danny
gamedanny
Posts
4
Registration date
Sunday June 23, 2013
Status
Member
Last seen
June 28, 2013
Jun 25, 2013 at 06:42 AM
Jun 25, 2013 at 06:42 AM
I have tried modifying the code but not luck!
gamedanny
Posts
4
Registration date
Sunday June 23, 2013
Status
Member
Last seen
June 28, 2013
Jun 28, 2013 at 11:49 AM
Jun 28, 2013 at 11:49 AM
bump
Didn't find the answer you are looking for?
Ask a question
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Jun 29, 2013 at 09:22 AM
Jun 29, 2013 at 09:22 AM
sample trivial data SHEET2
enter A1 1
a2 2
highlight A1:a2 and drag down upto about 161 rows (more ok)
AT THE BEGINNING OF THE MACRO THIS SHEET2 IS COPIED TO SHEET1
revised macro is
I am sending the file in address gisven below. see result in sheet1
http://speedy.sh/nh5eB/gamedanny-130629.xlsm
check and give feedback.
enter A1 1
a2 2
highlight A1:a2 and drag down upto about 161 rows (more ok)
AT THE BEGINNING OF THE MACRO THIS SHEET2 IS COPIED TO SHEET1
revised macro is
Sub test() Dim j As Long, r As Range Worksheets("sheet1").Cells.Clear Worksheets("sheet2").Cells.Copy Worksheets("sheet1").Range("A1") Worksheets("sheet1").Activate j = Cells(Rows.Count, "A").End(xlUp).Row ' 'MsgBox j Set r = Range("A1") Do 'MsgBox r.Address Set r = r.Offset(6, 0) ' MsgBox r.Address r.EntireRow.Insert Set r = r.Offset(45, 0) 'MsgBox r.Address r.EntireRow.Insert If r.Row > j Then Exit Do Loop MsgBox "macro over" End Sub
I am sending the file in address gisven below. see result in sheet1
http://speedy.sh/nh5eB/gamedanny-130629.xlsm
check and give feedback.