View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Flemming Dahl[_2_] Flemming Dahl[_2_] is offline
external usenet poster
 
Posts: 18
Default problem referring to Range and Cells

Your code only works for the ActiveSheet.
You say i works fine form Sheet 2 - Try select Sheet 1 before running it on
sheet 2 and then sheet1

This will work:

Sub test()
Worksheets("Sheet1").Activate
With Range(Cells(3, 1), Cells(3, 5))
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub


Cheers,
Flemming


"Kevin" wrote in message
...
The program halts and I get a Run-time error '1004' when I run the

following
code from Sheet1. But it works fine when I run it from Sheet2. Any

ideas?

Thanks.

Kevin

Sub test()
Dim Message As String
Message = MsgBox("This test # 1")
With Worksheets("Sheet2").Range(Cells(3, 1), Cells(3, 5))
Message = MsgBox("This test # 2")
With .Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End With
End Sub