VBA Loop through named Ranges - Copy paste as values one after the other

pthomas416

New Member
Joined
Apr 6, 2018
Messages
9
I have a workbook with several sheets that I have specified ranges for starting in A3 (same on every sheet) through column Q (row count varies). I have a sheet in the workbook that has all of the named ranges listed out in column A. I would like to write a macro that will look on sheets "Ranges" - where the list of all of the named ranges I want to copy is, go to the first named range, copy the information in A3:Q(?) and past it on a sheet named "Benefit". I have a header column, so the first pasted value start in the second row. I need it to loop through all of the named ranges listed on the sheet titled "Ranges" copying and pasting one after the other on the sheet titled "Benefit"

Anyone have any suggestions?
My Start:

{Sub ConsolData()
Dim Ranges As Range
Dim lastrowdata As Long
Dim ws As Worksheet: Set ws = Sheets("Benefit")

With Application
.Screenupdatingg = False
End With

For Each Ranges In Sheets("Ranges").Range("Ranges")
If Ranges.Value = "" Then
Exit For
Else
With Range(Ranges.Value)
lastrowdata = .Range("A:A").Find("*", [A1], , , , xlPrevious).Row
.Range("A4:Q" & lastrowdata).Copy
ws.Range("B:B").Find("*", [B1], , , , xlPrevious).Offset(1, 0).PasteSpecial xlPasteValues
End With
End If
Next Ranges

With Application
.ScreenUpdating = False
.CutCopyMode = False
End With
End Sub}
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
isn't the list of named ranges already indicating what the range that needs to be copied is? why do you need to set what last row of data is?
 
Upvote 0
If these are named ranges why do you need
copy the information in A3:Q(?)

I would think it would be Range("George").copy for example
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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