Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Formatting via VBA

I recorded a simple macro to change the format of a worksheet to "Accounting".

Cells.Select
Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"

But how do I "deselect" the page after the macro has executed? In other
words, when I created the macro I selected the entire spreadsheet, so when I
run the macro the entire worksheet remains selected after the macro runs.
What code can I put at the end of the macro so that the last cell that was
selected when the was run is reselected when it finishes. Or, if there's
better code to accomplish the reformatting of a spreadsheet that negates
having to reselect the cell I was working in I'd appreciate to have that.

Thanks.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 105
Default Formatting via VBA

Cells.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"
Daniel

I recorded a simple macro to change the format of a worksheet to
"Accounting".

Cells.Select
Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"

But how do I "deselect" the page after the macro has executed? In other
words, when I created the macro I selected the entire spreadsheet, so when I
run the macro the entire worksheet remains selected after the macro runs.
What code can I put at the end of the macro so that the last cell that was
selected when the was run is reselected when it finishes. Or, if there's
better code to accomplish the reformatting of a spreadsheet that negates
having to reselect the cell I was working in I'd appreciate to have that.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 55
Default Formatting via VBA

Daniel--this works perfectly. I appreciate your valuable help.


"Exceller" wrote:

I recorded a simple macro to change the format of a worksheet to "Accounting".

Cells.Select
Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"

But how do I "deselect" the page after the macro has executed? In other
words, when I created the macro I selected the entire spreadsheet, so when I
run the macro the entire worksheet remains selected after the macro runs.
What code can I put at the end of the macro so that the last cell that was
selected when the was run is reselected when it finishes. Or, if there's
better code to accomplish the reformatting of a spreadsheet that negates
having to reselect the cell I was working in I'd appreciate to have that.

Thanks.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Formatting via VBA

For future reference... when you use the macro recorder, it sees you do
every step; hence it saw you select the cells (first step) and then apply a
format to them (second step), so it gave you two separate lines like this...

Range.Select
Selection.DoSomethingToTheSelection [=][TheSomething]

where DoSomethingToTheSelection could be a method to execute against the
selection or, as in your case, an assignment of a value to one of the
selection's properties. The point is that it is almost always possible to
"bridge" the two statements at the Select/Selection to produce a single line
command like this...

Range.DoSomethingToThisSelection [=][TheSomething]

Very rarely does VBA actually make you select the range before doing
something to it; so, if you see that construction result from the macro
recorder, you should consider performing the above "bridging" of the two
lines as shown above to see VBA will allow it (your program won't jump
around as much, so it should be more efficient).

--
Rick (MVP - Excel)


"Exceller" wrote in message
...
Daniel--this works perfectly. I appreciate your valuable help.


"Exceller" wrote:

I recorded a simple macro to change the format of a worksheet to
"Accounting".

Cells.Select
Selection.NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""_);_(@_)"

But how do I "deselect" the page after the macro has executed? In other
words, when I created the macro I selected the entire spreadsheet, so
when I
run the macro the entire worksheet remains selected after the macro runs.
What code can I put at the end of the macro so that the last cell that
was
selected when the was run is reselected when it finishes. Or, if there's
better code to accomplish the reformatting of a spreadsheet that negates
having to reselect the cell I was working in I'd appreciate to have that.

Thanks.



Reply
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
How can I convert conditional formatting into explicit formatting? Patrick Harris Excel Discussion (Misc queries) 0 April 9th 09 12:00 AM
Find formatting in text in cell, insert tags around formatting. CarlC Excel Programming 2 February 27th 08 09:26 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
expanding custom formatting without removing existing cell formatting? Keith Excel Worksheet Functions 3 December 27th 06 01:54 PM
Decimal Formatting in Windows English vs European Formatting Drummer361 Excel Programming 3 August 7th 06 02:48 PM


All times are GMT +1. The time now is 01:29 PM.

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"