+ Reply to Thread
Results 1 to 10 of 10

VBA: Border arond

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    VBA: Border arond

    I need VBA to add to my macro to have it go down column D and have border put for 1st cell with data and border down until no more data and keep going down column D and doing the same thing. This first cell in column D with data will always start with Cat and the last row in the string will be Total. I don't want to do the whole table, just down border down column D. Thanks.

  2. #2
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: VBA: Border arond

    Try
    Sub Catotal1()
        Dim i As Long, j As Long
        With Columns("D")
            i = .Find(What:="Cat*", after:=.Cells(1, 1), LookIn:=xlValues).Row
            j = .Find(What:="Total", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
        End With
        Range(Cells(i, 4), Cells(j, 4)).Borders.LineStyle = xlContinuous
    End Sub
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: VBA: Border arond

    Give this a try:

    Sub Macro2()
        Set r1 = Columns("D:D").Find(What:="CAT", After:=Range("D1"), LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
            
        Set r2 = Columns("D:D").Find(What:="TOTAL", After:=Range("D1"), LookIn:=xlFormulas, _
            LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False, SearchFormat:=False)
        Range(r1, r2).Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .ColorIndex = 0
            .TintAndShade = 0
            .Weight = xlThin
        End With
        Selection.Borders(xlInsideVertical).LineStyle = xlNone
        Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
    End Sub
    Gary's Student

  4. #4
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,936

    Re: VBA: Border arond

    You can also do that with conditional formatting. Select Column D and use: =$D1<>"" and specity border...
    Ben Van Johnson

  5. #5
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: VBA: Border arond

    Assuming that Gary's Student's interpretation that you want an outside border around the whole range (I wasn't sure by your question (and I'm still not)) you can also try
    Sub Catotal2()
        Dim i As Long, j As Long
        With Columns("D")
            i = .Find(What:="Cat*", After:=.Cells(1, 1), LookIn:=xlValues).Row
            j = .Find(What:="Total", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row
        End With
        Range(Cells(i, 4), Cells(j, 4)).BorderAround ColorIndex:=3, Weight:=xlThick
    End Sub

  6. #6
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: VBA: Border arond

    Thanks for the help. Looking at all the tables, some are not the same. Can I make it go from "Total" in first cell in D and go don't until "" 1st blank cell and only do an outside border only? Thanks for help.

  7. #7
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: VBA: Border arond

    "Total" in first cell in D and go don't until ""
    Are you saying from D1 to last used cell in Column "D"?

  8. #8
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: VBA: Border arond

    here is what im looking for. thanks so much
    Attached Files Attached Files

  9. #9
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: VBA: Border arond

    Just knocking off for the night but I'll post this until someone comes up with something better

    Sub BorderAgain()
        Dim lRow As Long, c As Range
        lRow = Cells(Rows.Count, "D").End(xlUp).Row
        For Each c In Range("D1:D" & lRow)
            If c.Value = "Total" Or c.Value = "total" Then
                Range(c, c.End(xlDown)).BorderAround ColorIndex:=1
            End If
        Next
    End Sub

  10. #10
    Forum Contributor
    Join Date
    08-07-2013
    Location
    mo
    MS-Off Ver
    Excel 2010
    Posts
    453

    Re: VBA: Border arond

    That's it, your awesome

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Mysterious additional border to left of rows border?
    By Oppressed1 in forum Excel General
    Replies: 2
    Last Post: 10-10-2012, 03:22 PM
  2. Remove extra border and put all border in last row of generated output
    By cruise.alter in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-05-2012, 01:21 AM
  3. Replies: 1
    Last Post: 03-29-2011, 08:22 AM
  4. Replies: 2
    Last Post: 10-05-2005, 04:05 PM
  5. Replies: 0
    Last Post: 01-12-2005, 10:50 AM

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