Macros and Named Ranges

rob1987

New Member
Joined
Feb 14, 2011
Messages
39
Hello,

I am having trouble writing code based around named ranges. I have a spreadsheet with tabs named "overview" "jan" "feb" "march" and so on.

In "overview" A1 I have A, in A3 i have B and in A5 I have C. In "jan" I have named ranges A1, B1 and C1. In "feb" named ranges A2, B2 and C2, In "march" I have named ranges A3, B3 and C3 and so on. All these ranges appear in columns f:g and are twenty rows long, although there are some blank rows at the bottom of some of the ranges.

What I want to be able to do is set up a Macro which will copy the the rows which contain text in range A1 and paste them into a range named A on the "overview" tab (in column B and C). This will also add rows in so that B will still appear in column A but still with a one row gap between the last row of the range A.
I then want a Macro which will copy the non-blank rows in range A2 and insert the appropriate number of rows onto the bottom of range A and paste the contents of A2 here following on from A1, moving B down as appropriate.

Basically I want to be able to copy and paste range 1 onto the end of range 2 and range 2 to expand to include the data pasted from range 1 so range 3 can then be pasted onto the end of there...

I hope that makes sense... please can somebody help?
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
To put it more simpler maybe:

I know how to set up code to copy and paste range1 onto the end of rangeA but how do I expand Range A so it now includes the original contents of A and the new data copied in from 1?
 
Upvote 0
Maybe something like this

Code:
Range("A1:A100").Copy Destination:=Range("myName").Offset(1)
Range("myName").CurrentRegion.Name = "myName"
 
Upvote 0
You can resize a name like this:

Code:
    With Range("Range1")
        .Resize(.Rows.Count + Range("Range2").Rows.Count).Name = "Range1"
    End With
 
Upvote 0
Okay.. for future reference how should I differentiate between example hyperthetical named ranges?

Thank you very much for the code, it works in expanding the range. Is there any way to copy only the cells containing data from the range and ignore the blank ones?
 
Upvote 0
If you must use hypothetical names, use ones that are valid.

You can AutoFilter for NonBlanks and copy the visible cells.
 
Upvote 0

Forum statistics

Threads
1,224,508
Messages
6,179,189
Members
452,893
Latest member
denay

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