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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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,075
Messages
6,128,667
Members
449,462
Latest member
Chislobog

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