LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 48
Default Naming a range

On Sep 10, 3:30*pm, "Rick Rothstein"
wrote:
ActiveSheet.Range("A1").Select
ActiveCell.Offset(0, 1).Range("A1").Select


First off, the above two lines appear to select the cell immediately to the
right of the first specified range; that is, the first specified range is A1
and the cell that is ultimately selected is B1... I really don't know what
the intended purpose of that second Range("A1") is supposed to be doing. On
top of that, it is rarely necessary (and definitely not desirable) to select
a range of cells in order to operate on them. This single line of code
should what you have asked for...

ActiveSheet.Range("A1").Offset(0, 1).Name = TempNumber & "XXX"

Perhaps this previous posting of mine (a response to another person using
Select/Selection type constructions) will be of some help to you in your
future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

* * Range("C2:C8193").Select * * * * 'select cells to export
* * For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

* * For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)

"jeff" wrote in message

...
I posted this in a different form before. I appreciated the replies,
but they didn’t work for me. I will post this hoping that someone can
help me with this version of the problem.

ActiveSheet.Range("A1").Select
ActiveCell.Offset(0, 1).Range("A1").Select

‘What I’m looking for is to be able to name a range in the following
manner after the 2 ‘lines above.
‘The range name will be the word * * *“Junk” * * plus the value of the
range name *‘TempNumber
‘EXAMPLE: *if the value of TempNumber is “XXX”, then the new range
name
‘will be * * JunkXXX

Thanks for your help,
jeff


Thanks a bunch. I played with this and it works now. I DID have to
change something else. The value of TempNumber has a "#" in it, and I
guess you can't name a range with that symbol. Once I figured that
out, it all worked great.
Actually both solutions above work fine. I appreciate the effort.
Thanks again.
j.o.
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Naming a range hello Excel Discussion (Misc queries) 3 May 7th 07 07:01 PM
Naming a Range...? mastermind Excel Programming 3 May 16th 06 06:38 PM
naming a range Jo[_6_] Excel Programming 2 June 24th 04 09:39 PM
VB Code Naming a Range (range changes each time) krazylain Excel Programming 4 May 15th 04 12:41 PM
Naming a range cornishbloke[_5_] Excel Programming 1 December 15th 03 02:28 PM


All times are GMT +1. The time now is 02:35 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"