+ Reply to Thread
Results 1 to 6 of 6

Thread: Excel Formatting

  1. #1
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Excel Formatting

    Hi, Im new to the forum and require a bit of help with a VBA formatting issue.

    In my spreadsheet I have a number of columns, the information is exported from Access and works fine except for the fomating issue.

    I am trying to put a simple border around every cell in a row. The problem is that some of the cells have data in and some are blenak because the user hasnt filled them in for whatever reason. So in row 2 columns A-F have data in and have borders around them coloumns G - L dont have data in so dont have borders. I should probabley add thet row 1 contains headings and so columns A- L in that row all have data.

    Sub CreateBorder(ByRef r As Range)
    With r
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        .Borders(xlEdgeLeft).LineStyle = xlNone
        .Borders(xlEdgeTop).LineStyle = xlNone
        .Borders(xlEdgeBottom).LineStyle = xlNone
        .Borders(xlEdgeRight).LineStyle = xlNone
        .Borders(xlInsideVertical).LineStyle = xlNone
        .Borders(xlInsideHorizontal).LineStyle = xlNone
        .Borders(xlDiagonalDown).LineStyle = xlNone
        .Borders(xlDiagonalUp).LineStyle = xlNone
        .Borders(xlEdgeLeft).LineStyle = xlNone
        With .Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With .Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
            With .Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
            With .Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
            With .Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
            With .Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
    
    End With
    End Sub

  2. #2
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Excel Formatting

    Welcome to the forum.

    What is the issue you are facing with the above code?
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel Formatting

    The issue is that I only get borders around cells with data in them! Some rows have data in every column and the border appears around every cekk which is fine, but if the user omits a bit of data in cell E2 for arguements sake the whole row will have the border except that cell, which llos daft. i want the border to appear arounf every cell in the row up to the last column whatever that may be.

  4. #4
    Forum Moderator arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    4,396

    Re: Excel Formatting

    Instead of using the createborder sub, it will be easier if you select the area via code, for eg. range("A2:Z25").....You have not provided the earlier code before the border code. You can find the last row containing data and then assign the borders to it. If you are facing problems, attach a sample file so i can help you.
    Cheers,
    Arlette

    If I helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  5. #5
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Excel Formatting

    Sub CreateBorder(ByRef r As Range)
     With r.specialcells(2).Borders
      .LineStyle = xlContinuous
      .Weight = xlThin
      .ColorIndex = xlAutomatic
     End With
    End Sub



  6. #6
    Registered User
    Join Date
    01-23-2012
    Location
    Warminster, England
    MS-Off Ver
    Excel 2010
    Posts
    4

    Re: Excel Formatting

    I have attached the file, thansk for looking
    Attached Files Attached Files

+ 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.2.0