ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help (https://www.excelbanter.com/excel-programming/375065-help.html)

jutes.g

help
 
I'm new to VBA and I can't seem to get this to work:
Set testrange = ActiveWorkbook.Worksheets("Mysheet").Range(Cells(3 , 8),
Cells(300, 8))

it returns a 1004 error..


Ron de Bruin

help
 
Hi

Use this

With Worksheets("Mysheet")
Set testrange = .Range(.Cells(3, 8), .Cells(300, 8))
End With

In your code cells use the cells in the activesheet and not in the sheet Mysheet
see the dots before Cells now so it use the cells on the sheet Mysheet

You can also use

Set testrange = Worksheets("Mysheet").Range(Worksheets("Mysheet"). Cells(3, 8), Worksheets("Mysheet").Cells(300, 8))



--
Regards Ron de Bruin
http://www.rondebruin.nl



"jutes.g" wrote in message oups.com...
I'm new to VBA and I can't seem to get this to work:
Set testrange = ActiveWorkbook.Worksheets("Mysheet").Range(Cells(3 , 8),
Cells(300, 8))

it returns a 1004 error..





All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com