A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Macro question



 
 
Thread Tools Display Modes
  #1  
Old March 11th, 2010, 06:19 PM posted to microsoft.public.excel.worksheet.functions
Tina
external usenet poster
 
Posts: 350
Default Macro question

I need a macro that will add the text -0000 at the end of whatever text is in
that current cell.

For example Cell = 75154

I need to add -0000 at the end of this so then it will be

75154-0000

I have tried all the formating stuff, but the Zipcode cell format doesnt
work.
  #2  
Old March 11th, 2010, 06:37 PM posted to microsoft.public.excel.worksheet.functions
Roger Govier[_8_]
external usenet poster
 
Posts: 338
Default Macro question

Hi Tina

This event code will be activated if you double click on a cell.
If it is empty - it will ignore the cell.
If it already ends in "-0000" it will strip it off.
If not, it will add "-0000" to the existing value

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As
Boolean)
If ActiveCell = "" Then Exit Sub
If Right(ActiveCell, 5) = "-0000" Then
ActiveCell.Value = Left(ActiveCell, Len(ActiveCell) - 5)
Else
ActiveCell.Value = ActiveCell.Value & "-0000"
End If
End Sub

Copy the code above
Right click on sheet tabView code
Paste code into white pane
Alt + F11 to return to Excel

--
Regards
Roger Govier

Tina wrote:
I need a macro that will add the text -0000 at the end of whatever text is in
that current cell.

For example Cell = 75154

I need to add -0000 at the end of this so then it will be

75154-0000

I have tried all the formating stuff, but the Zipcode cell format doesnt
work.

  #3  
Old March 15th, 2010, 03:23 AM posted to microsoft.public.excel.worksheet.functions
Corey[_4_]
external usenet poster
 
Posts: 8
Default Macro question

Why use the format cell function.
Highlight the row or column of cells you want to format.
Right click and select Format Cells.
On the NUMBER Tab, click Custom.
In the Type box place:- @"-0000"
Use the {@} if text is placed int he cell or use the {#} if only numerical
values are used.

No need for a macro.

Corey....
"Tina" wrote in message
...
I need a macro that will add the text -0000 at the end of whatever text is
in
that current cell.

For example Cell = 75154

I need to add -0000 at the end of this so then it will be

75154-0000

I have tried all the formating stuff, but the Zipcode cell format doesnt
work.



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:08 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.