Error 1004

Scott_

New Member
Joined
Mar 29, 2018
Messages
4
Hi all,

I'm trying to select a range of cells in a data sheet defined by integers k and l. I need to select that range before I input it into a pivot table (code not shown here)

When I use the .Select property I get a Error 1004. Any advise would be welcome here.

ActiveSheet.Range(.Cells(k, 1), .Cells(l, 17)).Select

Thanks in advance,

Scott


' Code to select custom data range k to l.
Public Sub Create_Report()

'Define range of report
ww_from = Application.InputBox _
(prompt:="From what is the workweek do you want to report?", Type:=1)

ww_to = Application.InputBox _
(prompt:="To what workweek do you want to report?", Type:=1)


'Find first row of data set locations
With ThisWorkbook.Worksheets("Sheet1").Range("C:C")
Set First = .Find(ww_from)
'Locate data set for report by row number
If Not First Is Nothing Then k = First.Row


'Find last row of data set locations
Set Last = .Find(ww_to + 1)
'Locate data set for report by row number
If Not Last Is Nothing Then
l = Last.Row - 1

Else
l = k
End If


ActiveSheet.Range(.Cells(k, 1), .Cells(l, 17)).Select

End With



End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel.

try removing the . (period) from infront of .cells
Code:
ActiveSheet.Range(Cells(k, 1), Cells(l, 17)).Select
 
Upvote 0
Hi & welcome to MrExcel.

try removing the . (period) from infront of .cells
Code:
ActiveSheet.Range(Cells(k, 1), Cells(l, 17)).Select


Thanks Fluff,

That does clear up the error 1004 but the "Sheet1" never get's activated and the cells don't get selected.

What I'm trying to do is port the data in range k to l into a pivot table.

Any ideas?
 
Upvote 0
If you want to copy them try
Code:
.Range(.Cells(k, 1), .Cells(l, 17)).Copy [COLOR=#ff0000]Sheets("sheet2").Range("A1")[/COLOR]
Changing the part in red to match your destination
 
Upvote 0
Is Sheet1 the active sheet?

No, for some reason the sheet does not go active when the last line is executed. It's definitely active with the ThisWorkbook. line of code because I can see the First and Last load in edit watchlist.

Scott

'Find first row of data set locations
With ThisWorkbook.Worksheets("Sheet1").Range("C:C")
Set First = .Find(ww_from)
'Locate data set for report by row number
If Not First Is Nothing Then k = First.Row


'Find last row of data set locations
Set Last = .Find(ww_to + 1)
'Locate data set for report by row number
If Not Last Is Nothing Then
l = Last.Row - 1

Else
l = k
End If


ActiveSheet.Range(.Cells(k, 1), .Cells(l, 17)).Select

End With
 
Upvote 0
If it is not the activesheet then you need to see Fluff's last post.
The below will error because you are referencing 2 different sheets
Code:
ActiveSheet.Range(.Cells(k, 1), .Cells(l, 17)).Select
and you can't select on a sheet that isn't active.
 
Last edited:
Upvote 0
If it is not the activesheet then you need to see Fluff's last post.
The below will error because you are referencing 2 different sheets
Code:
ActiveSheet.Range(.Cells(k, 1), .Cells(l, 17)).Select
and you can't select on a sheet that isn't active.

Thanks much Mark,

This works:

ThisWorkbook.Worksheets("Sheet1").Activate
ActiveSheet.Range(Cells(k, 1), Cells(l, 17)).Copy Sheets("sheet2").Range("A1")

Scott
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

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