Selecting a variable range of cells

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!
 
Last edited:

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Try this:

sheetDatabase.Range("A" & i & ":AK" & i).Copy

or you can use this:

sheetDatabase.Range("A" & i,"AK" & i).Copy
 
Upvote 0

Forum statistics

Threads
1,216,737
Messages
6,132,436
Members
449,727
Latest member
Aby2024

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