Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 205
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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
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
How can I insert a true blank inst. of a non-blank zero string MF Excel Worksheet Functions 2 October 30th 09 01:58 PM
A logical test in the If function for blank, i.e., If blank? egii Excel Worksheet Functions 5 September 16th 09 11:46 AM
Insert blank line macro laidebug Excel Worksheet Functions 1 April 14th 06 11:56 PM
Macro To Insert Blank Row? rtidrtid Excel Discussion (Misc queries) 1 February 3rd 06 03:00 PM
Macro to insert blank lines Terry Pinnell Excel Discussion (Misc queries) 6 October 21st 05 11:21 PM


All times are GMT +1. The time now is 02:59 PM.

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"