ThatGuyNamedDean
New Member
- Joined
- Apr 16, 2015
- Messages
- 9
I am looking to copy a range of cells that is based on the value of a For loop and paste it to a new worksheet. I have been able to successfully do it with just one cell but when I look to extend this I can not figure out the context. Here is what I have so far...
Public Sub Test()
Dim sheetTool As Worksheet, sheetDatabase As Worksheet
Dim wkb As Workbook
Dim i As Integer
Set wkb = Workbooks("PSD_Volume_Prediction")
With wkb
Set sheetTool = .Sheets("Tool")
Set sheetDatabase = .Sheets("Database")
For i = 1 To 10
If sheetTool.Range("B3") = sheetDatabase.Range("A" & i) Then
sheetDatabase.Range("A:AK" & i).Copy
sheetTool.Range("B30").PasteSpecial
End If
Next i
End With
End Sub
The line that attempts to copy is what I am struggling with and have tried multiple things with no success.
sheetDatabase.Range("A" & i :"AK" & i).Copy
sheetDatabase.Range(""A" & i :"AK" & i").Copy
Also I am quite new to this site if there is an easier way to display code that would be helpful to learn. Thank you!
Public Sub Test()
Dim sheetTool As Worksheet, sheetDatabase As Worksheet
Dim wkb As Workbook
Dim i As Integer
Set wkb = Workbooks("PSD_Volume_Prediction")
With wkb
Set sheetTool = .Sheets("Tool")
Set sheetDatabase = .Sheets("Database")
For i = 1 To 10
If sheetTool.Range("B3") = sheetDatabase.Range("A" & i) Then
sheetDatabase.Range("A:AK" & i).Copy
sheetTool.Range("B30").PasteSpecial
End If
Next i
End With
End Sub
The line that attempts to copy is what I am struggling with and have tried multiple things with no success.
sheetDatabase.Range("A" & i :"AK" & i).Copy
sheetDatabase.Range(""A" & i :"AK" & i").Copy
Also I am quite new to this site if there is an easier way to display code that would be helpful to learn. Thank you!
Last edited: