View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jo Stein Jo Stein is offline
external usenet poster
 
Posts: 2
Default How to activate Sheet2?

This VBA code works OK if I run it inside the Sheet2,
but it fails if I try to start it with a command-button
located in Sheet1.

Sheet2.Cells(2, 4) = Sheet2.Cells(2, 3)
j = j - 1
Sheet2.Cells(j, 5) = Sheet2.Cells(j, 3)
' Sheets("Sheet2").Activate
Sheet2.Range(Cells(2, 1), Cells(j, 1)).Name = "filterA"
Sheet2.Range(Cells(2, 1), Cells(j, 2)).Name = "filterAB"
End Sub

It fails at this line
Sheet2.Range(Cells(2, 1), Cells(j, 1)).Name = "filterA"
and I get the message
Run-time error '1004'
Method 'Range' of object '_Worksheet' failed

I tried to add this line (it is now a comment)
Sheets("Sheet2").Activate
and that did no good.
--
jo