Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro code to test for blank row and insert blank row if false
Below is the code I am using to insert a blank row between text pasted to
Excel at various times. However, I would like to add a test if a blank row exists between rows of text, then do not insert another blank row. Here's what I currently have: Sub InsertRows() Dim RowNdx As Long Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowNdx = LastRow To 2 Step -1 Rows(RowNdx).Insert Next RowNdx End Sub Any ideas? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro code to test for blank row and insert blank row if false
Hi Mattie,
Try this: Sub InsertRows() Dim RowNdx As Long Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowNdx = LastRow To 2 Step -1 If Cells(RowNdx - 1, 1).Value < "" Then Rows(RowNdx).Insert Else RowNdx = RowNdx - 1 End If Next RowNdx End Sub Note that it only tests for a blank value in the respective cell of column A. Hope that helps Best regards John "Mattie" wrote in message ... Below is the code I am using to insert a blank row between text pasted to Excel at various times. However, I would like to add a test if a blank row exists between rows of text, then do not insert another blank row. Here's what I currently have: Sub InsertRows() Dim RowNdx As Long Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowNdx = LastRow To 2 Step -1 Rows(RowNdx).Insert Next RowNdx End Sub Any ideas? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Macro code to test for blank row and insert blank row if false
Perfect! Thank you.
Mattie "John" wrote: Hi Mattie, Try this: Sub InsertRows() Dim RowNdx As Long Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowNdx = LastRow To 2 Step -1 If Cells(RowNdx - 1, 1).Value < "" Then Rows(RowNdx).Insert Else RowNdx = RowNdx - 1 End If Next RowNdx End Sub Note that it only tests for a blank value in the respective cell of column A. Hope that helps Best regards John "Mattie" wrote in message ... Below is the code I am using to insert a blank row between text pasted to Excel at various times. However, I would like to add a test if a blank row exists between rows of text, then do not insert another blank row. Here's what I currently have: Sub InsertRows() Dim RowNdx As Long Dim LastRow As Long LastRow = Cells(Rows.Count, "A").End(xlUp).Row For RowNdx = LastRow To 2 Step -1 Rows(RowNdx).Insert Next RowNdx End Sub Any ideas? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I insert a true blank inst. of a non-blank zero string | Excel Worksheet Functions | |||
A logical test in the If function for blank, i.e., If blank? | Excel Worksheet Functions | |||
Insert blank line macro | Excel Worksheet Functions | |||
Macro To Insert Blank Row? | Excel Discussion (Misc queries) | |||
Macro to insert blank lines | Excel Discussion (Misc queries) |