+ Reply to Thread
Results 1 to 2 of 2

VBA Error 400

Hybrid View

AHawkins_Bjorksten VBA Error 400 03-04-2011, 02:57 PM
shg Re: VBA Error 400 03-04-2011, 05:14 PM
  1. #1
    Registered User
    Join Date
    03-04-2011
    Location
    Madison,WI
    MS-Off Ver
    Excel 2003
    Posts
    5

    VBA Error 400

    I am new to writing VBA scripts and I am having problems getting my scripts to run. My code is:
    Sub Cellborder()
    
    'Formats all cells, below the row with column headings, that have data with cell borders
    
    Dim nLastRow    As Long
    Dim nLastColumn As Long
    Dim nLastCell   As Long
    
    nLastRow = ActiveSheet.UsedRange.Rows.Count
    nLastCol = ActiveSheet.UsedRange.Columns.Count
    nLastCell = ActiveSheet.Cells(nLastRow, nLastCol)
    
        ActiveSheet.Range("A7").SpecialCells(xlCellTypeLastCell).Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlMedium
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
    End Sub
    When ever I try to run it, it comes up with a error 400. What could the problem be?
    Last edited by AHawkins_Bjorksten; 03-04-2011 at 03:55 PM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: VBA Error 400

    Try this:
    Sub Cellborder()
        With ActiveSheet.UsedRange
            With .Offset(1).Resize(.Rows.Count - 1).Borders
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
        End With
    End Sub
    Entia non sunt multiplicanda sine necessitate

+ 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