Need a macro to handle to events

I want to make any number that has nothing in front of it (in the Category column) bold face.  And then I also want to insert a blank row under it.  Can this be done with a macro?  I wouldn't know where to begin.

This is a small sampling of the worksheet:

Excel Sample
SteveL13Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You may try something like this...


Sub FormatColumnAndInsertRows()
Dim lr As Long, i As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, "K").End(xlUp).Row
For i = lr To 2 Step -1
    If Cells(i, "K") <> "" And Cells(i, "J") = "" Then
        Cells(i, "K").Font.Bold = True
        Rows(i + 1).Insert
    End If
Next i
Application.ScreenUpdating = True
End Sub

Open in new window

0
Martin LissOlder than dirtCommented:
Try this.

Sub BoldAndInsertLine()
Dim lngLastRow As Long
Dim lngRow As Long

lngLastRow = Range("K1048576").End(xlUp).Row

For lngRow = lngLastRow To 2 Step -1
    If IsEmpty(Cells(lngRow, "J")) Then
        Cells(lngRow, "K").Font.Bold = True
        Rows(lngRow + 1).Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    End If
Next
        
End Sub

Open in new window

0
SteveL13Author Commented:
I must not know what to do.  I copy/pasted both suggestions into a macro window and tried to run it but nothing happened.  I have the file saved as .xlsm

???
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Martin LissOlder than dirtCommented:
In this workbook click Ctrl+Shift+B.
29096485.xlsm
0
Martin LissOlder than dirtCommented:
To do the same in your workbook

Press Alt+F8 to open the "Macro" dialog window. Select the macro, click ‘Options…’,  hold down the Shift key and type the letter 'B' (or any other letter) and click ‘OK’. Then anytime you want to run the macro press Ctrl+Shift+B.

A command button or a shape used as a command button could be added to run it.
0
Martin LissOlder than dirtCommented:
If you can attach your workbook I can do it for you.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
You are supposed to place the code on a Standard Module like Module1.
Both the codes will work on whatever sheet is currently the active sheet. So make sure that the correct sheet is active when you run the macro.
0
SteveL13Author Commented:
Just isn't working.  Either solution.  My worksheet has data in A1 - D425.  (The header row is row 1.  Does this matter?
0
Martin LissOlder than dirtCommented:
If J is Category and K is Amount it should work. Please attach your workbook or a sanitized sample.
0
Martin LissOlder than dirtCommented:
Click the blue button and let me know if you see anything change.
29096485a.xlsm
0
SteveL13Author Commented:
Please see the attached file.  This is an example of the real file that I can't share because the data is confidential.  The real file has data in A1 through D245.. The header is row 1.
Book1.xlsm
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Please try this...
Sub FormatColumnAndInsertRows()
Dim lr As Long, i As Long
Application.ScreenUpdating = False
lr = Cells(Rows.Count, "D").End(xlUp).Row
For i = lr To 2 Step -1
    If Cells(i, "D") <> "" And Cells(i, "C") = "" Then
        Cells(i, "D").Font.Bold = True
        Rows(i + 1).Insert
    End If
Next i
Application.ScreenUpdating = True
End Sub

Open in new window


In the attached file, click the button called "Format Data" to run the code.
Book1.xlsm
0
Martin LissOlder than dirtCommented:
The reason nothing was happening in your workbook was that you told us that Category and Amount were in columns J and K and so the we provided code that referred to those columns. The attached workbook uses columns C and D.
29096485b.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SteveL13Author Commented:
Thank you to both of you.  Is much appreciated.
0
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
:)
0
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange Most Valuable Expert (MVE) 2015, 2017
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
              Experts Exchange Top Expert VBA (current)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Office

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.