简体   繁体   中英

Run-time error '1004' Range.boarders

Receiving an error with this segment of code. I am using code from Excel 2010 worksheet, where it works without issue, on an Excel 2013 computer. All of my libraries have updated correctly and we are not sure why this does not seem to be forward compatible.

With Me.Range("T3:Y196")

    .borders(xlEdgeBottom).Weight = xlThick
    .borders(xlEdgeLeft).Weight = xlThick
    .borders(xlEdgeRight).Weight = xlThick    '<--- error here
    .borders(xlEdgeTop).Weight = xlThick      '<--- once above code is commented out error occurs here

End With

Also receiving an error here:

With Range(ConvertColumnNumberToLetter(questionTextCol - 1) & CStr(myRow) & ":" & ConvertColumnNumberToLetter(instructionsCol) & CStr(myRow)).borders(xlEdgeTop)
'above Range gives same result as "T3:Y196" but I hard coded it to do some testing in the previous With Statement
    .LineStyle = xlContinuous    '<--- Error
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium           '<--- Error
End With

Now, both .LineStyle and .Weight work in other areas of the code so we are not sure what to do about this.

When I record a macro I get this:

With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .ColorIndex = 0
    .TintAndShade = 0
    .Weight = xlMedium
End With

When I add the range in it works to perfection (again this is on a clean sheet):

With Range("C2:I20")
    .Borders(xlEdgeBottom).Weight = xlMedium
    .Borders(xlEdgeRight).Weight = xlMedium
    .Borders(xlEdgeLeft).Weight = xlMedium
    .Borders(xlEdgeTop).Weight = xlThick
End With

Any assistance would be greatly appreciated. Thanks!

I don't know if this will help but instead of using with Me.Range try setting a sheet object and working from there. I tend to get less glitching this way. example

    Dim TheSheet as Worksheet
    Set TheSheet = Sheets("Your Sheet Name")
    With TheSheet.Range("T3:Y196")
         .borders(xlEdgeBottom).Weight = xlThick
         .borders(xlEdgeLeft).Weight = xlThick
         .borders(xlEdgeRight).Weight = xlThick    '<--- error here
         .borders(xlEdgeTop).Weight = xlThick  
    End With

The only other thing I can think of is merged cell issues, where half the cell is in the set range, and half the cell is not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM