VB coding to clear a selection?

S

StargateFan

I currently have the selection clear by changing the cursor location
to cell D2 (Range("D2").Select). So if the entire sheet had all the
cells selected, this would clear the selection but would also move to
another location. I actually need the active cell to remain the same
as before the macro was invoked, but don't know the VB code for this.

Thanks for any help in advance.
 
C

CLR

Maybe.............

Range("A1:A5").Select
Selection.ClearContents


Vaya con Dios,
Chuck, CABGx3
 
B

Bob Phillips

I think Chuck would mean

Range("A1:A5").ClearContents

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
N

NC

hi stargatefan
do you want clear the contents or just get rid of the selected
cells(i.e.deactivating them) & again activate the cell on which you was
working before.

you can do this by using a temporary range which you can declare equal
to your active cell(s) then run the macro & then again activating this
temporary range.

Regards
NC
 
S

StargateFan

I think Chuck would mean

Range("A1:A5").ClearContents

YIIKES! <g> That deleted the contents as well as clearing the
selection! Any way to _just_ de-select (clear the selection) while
keeping the "cursor" in the same cell as before invoking the macro?

Thanks much!
 
S

StargateFan


Very interesting, brings up the question on whether my
keystrokes-recorded macro would work, then, without selecting the
_entire_ worksheet. Seems like it would, but thought I'd ask. I
invoke this toolbar macro after copy/pasting a bunch of data into
Excel. Since invoking with full attributes means that the data
structure remains intact (very important), I created the macro to
quickly and easily re-format the pasted in text to what the rest of
the sheet is for easier editing and for a proper final look.

But as I'm working on different rows, the problem has been that the
way I've been clearing the selection itself is to just hit Ctrl+Home
which takes me to the top cell in the sheet. Not sure that this
situation falls under the troubles the website above talks about as
the _entire_ worksheet is selected.

Thanks!
 
S

StargateFan

hi stargatefan
do you want clear the contents or just get rid of the selected
cells(i.e.deactivating them) & again activate the cell on which you was
working before.

Ah, the problem was in the terminology. I'm actually just
de-activating the selection again.
you can do this by using a temporary range which you can declare equal
to your active cell(s) then run the macro & then again activating this
temporary range.

Lordy, that's beyond my limited VB knowledge! <g> Ah well, I'll just
keep working with what I have, I guess, unless/until something else
comes along.

Thanks much!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top