Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel macro to add /'s to a cell value.

I'm trying to get 3 /'s in an existing cell value. The value for example
would be 01232003 and I want the macro to insert /'s so it turns out to
be 01/23/2003.

What I've been experimenting with is this:

n = "0"
For Each cell In Selection
cell.Value = Left(cell.Value, 2) & "/" & Left(cell.Value, 2) & "/" &
Left(cell.Value, 4)


But this just results in 11/11/1122. It seems to be starting over from
the far left side with each "Left(cell.Value, *).

Any ideas?

Thanks!
RF

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Excel macro to add /'s to a cell value.


you might rather want to use

cell.Value = "=date(" & Right(cell.Value, 4) & "," & Left(cell.Value
2) & "," &
mid(cell.Value, 3, 2) & ")"

to convert into date,

or if you want to use your method, it should be
mid(cell.Value, 3, 2) & "/" & Left(cell.Value, 2) & "/"
Right(cell.Value, 4)

or as you require

maybe you might want to put a ' before the entire text to retain th
way you want to use it.

- Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=27585

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Excel macro to add /'s to a cell value.

You could try just selecting the range that you want to change, and use:
1) Data | Text to Columns
2) Select either Delimited or Fixed Width, it makes no difference
3) Hit "Next" then "Next" again
4) On the last screen, select the "Date" option, and the date format of your
choice
5) Hit "Finish"

Or, if you really do need a macro (this works for UK date format -
dd/mm/yyyy):-
Selection.TextToColumns _
Destination:=Selection, _
DataType:=xlFixedWidth, _
FieldInfo:=Array(0, 4) ' note for US dates, use 0,3 here


HTH

Alan P


"Robert Franks" wrote in message
...
I'm trying to get 3 /'s in an existing cell value. The value for example
would be 01232003 and I want the macro to insert /'s so it turns out to
be 01/23/2003.

What I've been experimenting with is this:

n = "0"
For Each cell In Selection
cell.Value = Left(cell.Value, 2) & "/" & Left(cell.Value, 2) & "/" &
Left(cell.Value, 4)


But this just results in 11/11/1122. It seems to be starting over from
the far left side with each "Left(cell.Value, *).

Any ideas?

Thanks!
RF

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
copy excel cell to cell in word table using excel macro jthurnwps Excel Discussion (Misc queries) 0 July 21st 06 07:11 PM
How to set variable to cell value in excel macro most xlent Excel Discussion (Misc queries) 6 October 27th 05 06:52 PM
enter a new value into a cell using macro in excel cath Excel Discussion (Misc queries) 2 April 12th 05 11:32 PM
Macro adds 1 to Cell in excel Xispo[_2_] Excel Programming 4 November 12th 03 07:07 PM


All times are GMT +1. The time now is 12:15 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"