+ Reply to Thread
Results 1 to 5 of 5

Macro to add a border if cell is not blank

Hybrid View

  1. #1
    Registered User
    Join Date
    04-03-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to add a border if cell is not blank

    Hi,

    I am looking to create a macro that adds a top border to the whole row if the first cell of that row is NOT blank. I would like this macro to run on all rows that contain text (there's about 8000).

    I've looked around the forums and can't find anything that fits my requirements closely enough for me to tailor as I'm quite new to programming.

    Appreciate any help anyone can offer.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro to add a border if cell is not blank

    for example
    Sub ert()
    Dim r As Range
    Application.ScreenUpdating = 0
    'On Error Resume Next
    For Each r In Range("A1" & Cells(Rows.Count, 1).End(xlUp)).SpecialCells(2)
        r.EntireRow.Borders(xlEdgeTop).LineStyle = xlContinuous
    Next
    Application.ScreenUpdating = 1
    End Sub

  3. #3
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,524

    Re: Macro to add a border if cell is not blank

    Quote Originally Posted by nilem View Post
    for example
    ........Each r In Range("A1" & Cells(Rows.Count, 1).....
    Hi nilem,
    Are you sure about the "&"

  4. #4
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro to add a border if cell is not blank

    Hi davesexcel,
    No, I'm not sure. Strange, but it works for me.

    stonefish150, change this line:
    For Each r In Range("A1", Cells(Rows.Count, 1).End(xlUp)).SpecialCells(2)

  5. #5
    Registered User
    Join Date
    04-03-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Macro to add a border if cell is not blank

    Hi guys. It works great- thanks very much for your help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1