Resz7
08-08-2014, 10:52 AM
Hi everyone! I'm receiving Error 1004 at these 2 lines:
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
What am I doing wrong? Thanks in advance!
Option Explicit
Private Sub CommandButton1_Click()
'This code pulls only the data we need from Sheet1 and puts it on Sheet6
Dim rngFind As Range, firstAddress As String
Const strFindMe As String = "Ship To:"
'Makes sure cell selections are where they're supposed to be
Worksheets("Sheet6").Select
Worksheets("Sheet6").Range("A2").Select
Worksheets("Sheet1").Select
Worksheets("Sheet1").Range("A1").Select
'Find Next loop. Searches for "Ship To:" and selects data underneath it
With Worksheets("Sheet1").Cells
Set rngFind = .Find(what:=strFindMe, LookIn:=xlValues)
If Not rngFind Is Nothing Then
firstAddress = rngFind.Address
Do
rngFind.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet6").Select
ActiveSheet.Paste
Worksheets("Sheet6").Range("A20000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(2, 0).Select
Sheets("Sheet1").Select
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> firstAddress
End If
End With
Worksheets("Sheet6").Select
Worksheets("Sheet6").Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
What am I doing wrong? Thanks in advance!
Option Explicit
Private Sub CommandButton1_Click()
'This code pulls only the data we need from Sheet1 and puts it on Sheet6
Dim rngFind As Range, firstAddress As String
Const strFindMe As String = "Ship To:"
'Makes sure cell selections are where they're supposed to be
Worksheets("Sheet6").Select
Worksheets("Sheet6").Range("A2").Select
Worksheets("Sheet1").Select
Worksheets("Sheet1").Range("A1").Select
'Find Next loop. Searches for "Ship To:" and selects data underneath it
With Worksheets("Sheet1").Cells
Set rngFind = .Find(what:=strFindMe, LookIn:=xlValues)
If Not rngFind Is Nothing Then
firstAddress = rngFind.Address
Do
rngFind.Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("Sheet6").Select
ActiveSheet.Paste
Worksheets("Sheet6").Range("A20000").Select
Selection.End(xlUp).Select
ActiveCell.Offset(2, 0).Select
Sheets("Sheet1").Select
Set rngFind = .FindNext(rngFind)
Loop While Not rngFind Is Nothing And rngFind.Address <> firstAddress
End If
End With
Worksheets("Sheet6").Select
Worksheets("Sheet6").Range("A1").Select