Cowlers


Hello All,

I have been trying to create a named range using a button in one worksheet to create the range in another worksheet but have been having some problems. Please find below my coding for this:

ActiveWorkbook.Names.Add _

Name:="Users", _

RefersTo:=Worksheets("Data Sheet").Range(Cells(3, 4), Cells(e, 4))

Where variable 'e' has already been defined in the code as an integer.

For some reason I keep getting an error message whenever I try to execute this code:

Run-time error '1004':

Application-defined or object-defined error

I have a little experience with VBA but am still learning so if anyone could help me out with this it would be very much appreciated!

Many thanks for your time in advance




Re: Creating a named range using cells from another worksheet

Shasur


Even though you would have declared that as integer, you wouldn't have assigned a value

Hence it will be taking '0' as default and trying to get the cell cells(0,4), which throws the error

Code Snippet

Sub testit()
Dim e As Integer
e = 4
ActiveWorkbook.Names.Add _
Name:="Users", _
RefersTo:=Worksheets("Data Sheet").Range(Cells(3, 4), Cells(e, 4))
End Sub

The above should solve the problem

Cheers

Shasur







Re: Creating a named range using cells from another worksheet

Cowlers

Thanks a lot for your help Shasur,

Best regards,

Dan