I need to copy a range selection from one sheet to another.
The range is dynamic based on .Find
results. I am able to pass all the required data into variables, but getting those string variables (both Column and Row values) into the Range to copy gives me
"Run Time Error 1004: PasteSpecial method of Range class failed ..."
My full code:
Private Sub AutoFill_Week_One()
Dim Well_1 As Range
Dim GasComp As Range
Dim gRow As Integer
Dim lRow As Integer
Dim GsRow As String
Dim LsRow As String
Dim GsDate As String
Dim LsDate As String
Dim GsRngS As String
Dim GsRngE As String
Dim LsRngS As String
Dim LsRngE As String
Dim GsComp As String
Dim LsComp As String
With Sheets("CSV Import")
Set Well_1 = Range("O1:O200").Find("102040307310W600")
Well_1.Activate
gRow = ActiveCell.Row
GsRow = "A" & CStr(gRow)
If Range(GsRow).value = "G" And Well_1.value = "102040307310W600" Then
GsDate = "E" & CStr(gRow)
MsgBox GsDate
Range(GsDate).Copy
Sheets("Week One").Range("F31").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
GsRngS = "T" & CStr(gRow)
GsRngE = "AG" & CStr(gRow)
GsComp = GsRngS & ":" & GsRngE
MsgBox GsComp
Set GasComp = .Range(GsComp)
GasComp.Copy
Sheets("Week One").Range("F33:F46").PasteSpecial _
Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End If
Set Well_1 = Range("O1:O200").FindNext(Well_1)
Well_1.Activate
lRow = ActiveCell.Row
LsRow = "A" & CStr(lRow)
If Range(LsRow).value = "L" And Well_1.value = "102040307310W600" Then
MsgBox "Liquid"
End If
End With
End Sub
I tried arrays, .Offset
and every other thing I could think of.
Hey BigBen that transfer is working! But I can't get the syntax to transfer them to a vertical range (F33:F46) they are only transferring horizontally!
With ThisWorkbook.Sheets("CSV Import").Range(GsComp)
Sheets("Week One").Cells(33, 6).End(xlUp).Cells(46, 6).Resize(.Rows.Count, .Columns.Count) = .value
End With