Error when using trying to add a range to a variable

Kevali

New Member
Joined
Aug 21, 2006
Messages
15
Every time I use the set command to point to a range of cells ready for me to load an array into them I get 1004 error code.

Any Ideas.

Snipit of code
Dim Reportrange as Range

Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Select
Sheets(Sheets.Count).Name = reportname
Worksheets(reportname).Select
Range("A1").Select
Set ReportRange = worksheets(reportname).Range(Range(Cells(UBound(SickReport, 2), 1), Cells(1, 6))

I get error code 1004?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Try like this

Code:
Dim Reportrange As Range

Sheets.Add After:=Sheets(Sheets.Count)
With Sheets(Sheets.Count)
    .Name = "reportname"
    Set Reportrange = .Range(.Cells(UBound(SickReport, 2), 1), .Cells(1, 6))
End With
 
Upvote 0
Try:

Code:
Dim Reportrange As Range
Sheets.Add After:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = reportname
With Sheets(reportname)
    Set Reportrange = .Range(.Cells(UBound(SickReport, 2), 1), .Cells(1, 6))
End With

You had an extra Range() in there, also, you need to qualify each of the Cells() reference with the sheet name
 
Upvote 0
The code now works, I think the extra range crept in as I was trying al sorts of range options to refer to except qualifying the sheet ref as well.

Thanks Guys.
 
Upvote 0
Hi

Also:

Code:
Dim Reportrange As Range
 
With Sheets.Add(After:=Sheets(Sheets.Count))
    .Name = "reportname"
    Set Reportrange = .Range(.Cells(UBound(SickReport, 2), 1), .Cells(1, 6))
End With
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top