Copy Application.Union(c.Offset(0, 1), c.Offset(0, 2)... to a list onsame & another sheet

  • Thread starter Thread starter Howard
  • Start date Start date
Just want to emphasize that using defined name for the search string
col doesn't break your code...



Dim lSearchStrCol&

lSearchStrCol = Range("SearchStrings").Column

LRow = .Cells(.Rows.Count, lSearchStrCol).End(xlUp).Row



OR



LRow = .Cells(.Rows.Count, Range("SearchStrings").Column).End(xlUp).Row



..because Excel will always know where it is!


Okay, I think a little light is making its way into my head here.

So I would name the column (or the range within the column) "SearchStrings"?

And if I move the column of strings from A to G like I did here, I would just change the range reference of the name "SearchStrings" in the Name Manager?

Howard
 
Just want to emphasize that using defined name for the search string
Okay, I think a little light is making its way into my head here.

So I would name the column (or the range within the column)
"SearchStrings"?

And if I move the column of strings from A to G like I did here, I
would just change the range reference of the name "SearchStrings" in
the Name Manager?

Howard

No! Excel will automagically update the ref for you!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
No! Excel will automagically update the ref for you!
How does Excel know I decided I want col G instead of col A?

Howard

When you design the name Excel creates absolute refs ($) by default.
When you move the range, Excel updates the absolute refs to the new
location. This has been standard behavior for as far back as I can
remember!

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
When you design the name Excel creates absolute refs ($) by default.

When you move the range, Excel updates the absolute refs to the new

location. This has been standard behavior for as far back as I can

remember!

Okay, I think I got it. I just now selected A1:A5 and named it MyString.

If I select A1:A4 and drag it to G, range stays A1:A5.
If I select A1:A5 (or more, say A1:A8) and drag to G the new reference is G1:G5 and the code looks for MyString where ever it is

Howard
 
If I select A1:A4 and drag it to G, range stays A1:A5.
If I select A1:A5 (or more, say A1:A8) and drag to G the new
reference is G1:G5 and the code looks for MyString where ever it is

Well.., you should be explicit when stating range refs. In your
example, the original ref was...

=$A$1:$A$5

...and the new ref after moving is...

=$G$1:$G$5

...where this is a *fully absolute* ref. What you posted was *fully
relative* refs. What determines this is the *$* symbol and where it is
positioned with respect to the col/row labels in the range address.

Also, you didn't state that you *explicitly* forced local (sheet level)
scope by including the sheetname when you typed the range name in the
Namebox. The result is the defined named has global (workbook level)
scope which you would *only use when absolutely necessary* if you
follow using 'best practices' in your work!


There are 2 more ref types...

ColAbsolute/RowRelative: e.g.: $A1:$A5

ColRelative/RowAbsolute: e.g.: A$1:A$5

...both of which present specific behavior *relative* to the
non-absolute portion of the ref, and *absolute* to the non-relative
portion.

<Usage example>
Say you have a table of amounts on Sheet1 that you need a simple SUM
formula at the bottom. This table has a headings row.

Select A2

Defined name: 'Sheet1'!Hdr_Row
ReferTo: =A$1
Description: Creates a colRelative/rowAbsolute ref *relative* to the
same col as the currently active cell.

Defined name: 'Sheet1'!FirstCell
ReferTo: =OFFSET(Hdr_Row,1,0)
Description: Creates a colRelative/rowAbsolute ref *relative* to the
same col as the currently active cell, absolute to the row below
the
headings row.

Defined name: 'Sheet1'!LastCell
ReferTo: =A1
Description: Creates a fully relative ref *relative* to the
same col as the currently active cell and the row before the
currently active cell.

So your table has say 10 rows of amounts and the totals go in row 12 so
that the table area is contiguous headings to totals. Select all the
cells to receive totals in the totals row and type the following
formula...

=SUM(FirstRow:LastRow)

...then while holding down the Ctrl key, press Enter to put the formula
into all selected cells in one shot.

Now you can insert/delete rows anywhere between the headings row and
the totals row without breaking anything.

Note that the formula reads the same in each totals cell, and it's
self-explanatory as to what cells are involved. IMO, this makes for
easier understanding of how the formula works compared to using cell
addresses that have to be followed in order for the user to figure it
out!

Note that all the named ranges have local scope, allowing the same
names to be used on other sheets with similar requirements.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Okay, so I should do the naming using Define Name where I can select the sheet name from the Scope drop down.

Seems to me the default is *fully absolute* as the name always shows up in the name manager $A$1:$A$5...

I think I'm getting more or less what you are saying, just need to start trying to use it more often.

Howard
 
Okay, so I should do the naming using Define Name where I can select
the sheet name from the Scope drop down.

Seems to me the default is *fully absolute* as the name always shows
up in the name manager $A$1:$A$5...

I think I'm getting more or less what you are saying, just need to
start trying to use it more often.

Howard

Yes, fully absolute is the default ref type. You'll have to manually
configure if you want to use one of the other ref types.

For fully absolute refs you can just type in the Namebox left of the
FormulaBar. Just remember to prepend the sheetname as shown for
assigning local scope. Note that if there's no spaces in the sheetname
then the apostrophes are not required.

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
 
Back
Top