Solved Looking 2 insert a row through a macro if a cell has FALSE

Microsoft Office excel 2007
July 23, 2012 at 23:02:20
Specs: Windows 7
I have close to 1000-1500 Rows of information/data for client say A, B, C,D, etc in column "R". Each client has say 5-20 rows. I need to differenciate each client by inserting a row. As of now, what i tried is that I added a formula on the last column (Column "V") to say =IF(R3=R2,TRUE) it compares the next client is equal to the same row's client and results and true or false.

Now comes my question, Is possible to add a row under every FALSE sign in column to diffrenciate as I need to put a sum function. after every client. I tried googling and all I got is this can be done only in MAcros, and frankly im not that good in Macros.

See More: Looking 2 insert a row through a macro if a cell has FALSE

Report •

July 24, 2012 at 02:35:10
✔ Best Answer
The reason you can only find macro based solutions is because it can only be done with macros. Formula can only return values, they can't perform actions.

The code found at this site was written to look at Column A, but I modified it to look at Column R. I've also included the instructions on how to use to macro from this site and included them below. You don't need your TRUE FALSE column since the macro can use the changes in Column R to determine where to insert the rows.

Sub InsertRows()
  Dim r As Long, mcol As String, i As Long

' find last used cell in Column R
  r = Cells(Rows.Count, "R").End(xlUp).Row

 ' get value of  last used cell in column R
  mcol = Cells(r, "R").Value

 ' insert rows by looping from bottom
  For i = r To 2 Step -1
     If Cells(i, "R").Value <> mcol Then
       mcol = Cells(i, "R").Value
        Rows(i + 1).Insert
     End If
  Next i

End Sub

How to use this code:
Go to Developer Ribbon...Visual Basic (Alt+F11)
A new window will open.
Go to Insert>Module
Copy and paste the above code in the pane that opens.
Close the window.
Back in your Excel worksheet.
Go to Developer Ribbon...Macro's (Alt+F8)
A new small window will open.
Double click "InsertRows" to see the result of the code.

If something is still unclear then post back.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.

Report •
Related Solutions

Ask Question