if statement in a macro

  • Thread starter Thread starter arowland \(removethis\)
  • Start date Start date
A

arowland \(removethis\)

I have a list 4 columns wide that I need to group by the
characters in column A. Each group needs 4 lines
followed by a fifth blank line. Some groups may only
have 1 line of information and some may have 4, 3, or 2.
I tried to do an if statement that would ask if A1 = A4
then insert a blank line, otherwise ask if A1 = A3 then
insert 2 blank lines, otherwise ask if A1=A2 then insert
3 blank lines, otherwise insert 4 blank lines. Go to the
next line of text and do the if statement again until
there is not any text left. There could be up to 500
lines of text. Can someone please help me!!
thanks
 
Hi
try the following macro. It tests column A and inserts a blank row if
the values change
Sub insert_rows()
Dim lastrow As Long
Dim row_index As Long

lastrow = ActiveSheet.Cells(Rows.count, "A").End(xlUp).row
For row_index = lastrow - 1 To 1 Step -1
If Cells(row_index, "A").Value <> Cells(row_index + 1, "A").Value
Then
Cells(row_index + 1, "A").EntireRow.Insert (xlShiftDown)
End If
Next
End Sub

--
Regards
Frank Kabel
Frankfurt, Germany

"arowland (removethis) @heyco.org"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top