Insert row above rows containing certain information

afterdinnerspeaker

Board Regular
Joined
Jan 10, 2019
Messages
70
I posted this to Excel Forum earlier today but unable to get Macro to work satisfactorily...please HELP!

Hi there folks!

Just wondering if anyone could help me with the following tasks:

• Insert one row above each row containing a “number” in column “C”
• Insert one row above each of the two rows containing headings “TOTAL REVENUE” and “TOTAL EXPENSE” in column “B”
• Highlight the two instances of the one word headings “REVENUE” and “EXPENSE” (currently but not always in row #3 and row #13 ) in “light green”
PLEASE NOTE: The words "REVENUE" & "EXPENSE" span both column B & C in their respective rows


I attached a sample of the spreadsheet.

Many thanks in advance,

Jerry
<fieldset class="postcontent"><legend>
paperclip.png
Attached Files</legend>
</fieldset>
 
Last edited:

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Are the numbers actually numbers or Text appearing as numbers ??
 
Upvote 0
Looks like imported data ??
There is an apostrophe in front of all the numbers ??
 
Upvote 0
Maybe this

Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For r = lr To 3 Step -1
    If Len(Range("C" & r)) = 4 Or Range("B" & r).Value = "TOTAL REVENUE" Or Range("B" & r).Value = "TOTAL EXPENSE" Then
        Rows(r).Insert
    End If
    If Range("B" & r).Value = "REVENUE" Or Range("B" & r).Value = "EXPENSE" Then
        With Range("B" & r).Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 5296274
        End With
    End If
Next r
End Sub
 
Upvote 0
Thanks Michael! Sorry I didn't get back to you regarding the "imported" data question. The spreadsheet was imported from the Sage Simply Accounting program.

But, good news about your solution...everything works EXCEPT only half of the words "REVENUE" & "EXPENSE" get highlighted. I'm sure this is because these cells overflow to the adjacent cells.

Is there any way around this?
 
Upvote 0
USe

Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "B").End(xlUp).Row
For r = lr To 3 Step -1
    If Len(Range("C" & r)) = 4 Or Range("B" & r).Value = "TOTAL REVENUE" Or Range("B" & r).Value = "TOTAL EXPENSE" Then
        Rows(r).Insert
    End If
    If Range("B" & r).Value = "REVENUE" Or Range("B" & r).Value = "EXPENSE" Then
        With Range("B" & r & ":C" & r).Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .Color = 5296274
        End With
    End If
Next r
End Sub
 
Upvote 0
OMG!! You did it so fast & with so little code! This amazes me...thank you so much for your help!

I want you to know how much I appreciate your time & effort and will do whatever I can to acknowledge it.

Cheers,

Jerry
 
Last edited:
Upvote 0
Hi again Michael!

So sorry to ask you another question with regard to the code you wrote for me.

Would it be possible to make another adjustment to the code to also BOLD each of the rows containing those 4-digit numbers?

Many thanks again,

Jerry
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,550
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top