Hello to all you Excel gurus,
I am using the following code in a larger macro:
For Each RngCell In Rng1
If RngCell.Value = “XYZ Corp” Then
x = RngCell.Row
** With ActiveWorkbook.Sheets(v).Range(Cells(x, 1), Cells(x, c))**
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeLeft).ColorIndex = xlAutomatic
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeTop).ColorIndex = xlAutomatic
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlEdgeBottom).ColorIndex = xlAutomatic
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeRight).ColorIndex = xlAutomatic
End With
End If
Next RngCell
Note the line with the asterisks (fourth line down). This is the problem line. This line will not execute unless the specific sheet is selected. The macro comes to a stop if I try to run it. It gives a Run-time 1004 error. However if I then select the particular sheet (whatever v is), the line will execute properly, but then the same thing happens on the next worksheet.
I haven’t been able to find anything in literature on this, so I don’t know how to resolve it. All I would like to do is be able to execute the macro without having to select each worksheet.
Thanks in advance for any and all assistance…