![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
I have a list of consecutive dates running down column A in dd/mm/yy format. I am trying to insert 2 rows after every Sunday. My feeble attempt below completely failed, would appreciate any suggestions.
Thanks Matt Dim irow As Long irow = 1 Do While Cells(irow, 2) <> "" If Format(Range("A" & irow, "dddd")) = "Monday" Then Selection.EntireRow.Insert Selection.EntireRow.Insert End If irow = irow + 1 Loop End Sub |
|
|
|
|
|
#2 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Hi Matt
I was going to write a Loop, but you will be flooded with these soon. Here is a much quicker method. Sub Doit() Dim rRange As Range Set rRange = Range("B8:B" & Range("A65536").End(xlUp).Row) rRange.FormulaR1C1 = "=IF(AND(WEEKDAY(RC[-1])=1,R[-7]C<>1),1)" rRange = rRange.Value rRange.SpecialCells(xlCellTypeConstants, xlNumbers).EntireRow.Insert rRange.Clear End Sub Just ensure Column B is empty when you run it. |
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Dave you're a legend! Cheers
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Dave
The code works great how would I amend it to insert 2 rows instead of 1? thanks Matt |
|
|
|
|
|
#5 |
|
Board Regular
Join Date: Feb 2002
Location: England
Posts: 212
|
Ignore last post, have resolved
|
|
|
|
|
|
#6 |
|
Banned
Join Date: Feb 2002
Posts: 1,582
|
Oh well, better late than never.
Sub Doit() Dim rRange As Range Set rRange = Range("B8:B" & Range("A65536").End(xlUp).Row) rRange.FormulaR1C1 = "=IF(AND(WEEKDAY(RC[-1])=1,R[-7]C<>1),1)" rRange = rRange.Value With rRange.SpecialCells(xlCellTypeConstants, xlNumbers) .EntireRow.Insert .EntireRow.Insert End With rRange.Clear End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|