View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
Stefi Stefi is offline
external usenet poster
 
Posts: 2,646
Default How to use macro to edit data in Excel cells

Hi Annamalai,

Sorry, in my previous post I made an error: 11.06.06 in US style means 6th
of November, 2006.

Try this:
If your Windows language setting is US English with / as date separator and
11.06.06 means 11th of June, 2006 then use this sub:

Sub DateConv()
Selection.ColumnWidth = 11
For Each cell In Selection
If cell.Value = "" Then Exit For
x = Mid(cell, 4, 2) & "/" & Left(cell, 2) & "/" & Right(cell, 2)
cell.NumberFormat = "dd-mmm-yyyy"
cell.Value = DateValue(x)
Next cell
End Sub

If 11.06.06 means 6th of November, 2006 then use this sub: .

Sub DateConv()
Selection.ColumnWidth = 11
For Each cell In Selection
If cell.Value = "" Then Exit For
x = Replace(cell, ".", "/")
cell.NumberFormat = "dd-mmm-yyyy"
cell.Value = DateValue(x)
Next cell
End Sub

Regards,
Stefi


€˛Stefi€¯ ezt Ć*rta:

Does that mean that 11.06.06 in your example is a UK/India style date meaning
11th of June, 2006?
Or the problem is that it is a US style date meaning 6th of September, 2006?
One more question: How are cells containing these dates formatted? Text?
General?


Stefi


€˛Annamalai€¯ ezt Ć*rta:

Thanks for your reply.
I have U.S. (English) for dictionary in my computer. In India, the popular
date format is dd.mm.yyyy.
I tried to use your macro but did not succeed.
I will check again and come to you.
Annamalai
xxxxxxxxxxxxxxxxxxxxxxxxxxxxx

"Stefi" wrote:

Hi Annamalai,

From your examples I supposed that you have UK English language setting (in
Windows Regional settings). Post if it's not true! Customize it by setting
date separator to "." (fullstop). Then you can use this macro. Select ALL
cells (say a column) you want to convert, then run the macro!

Sub DateConv()
For Each cell In Selection
Selection.ColumnWidth = 11
If cell.Value = "" Then Exit For
x = cell.Value
cell.NumberFormat = "dd-mmm-yyyy"
cell.Value = DateValue(x)
Next cell
End Sub


Regards,
Stefi

€˛€¯ ezt Ć*rta:

Aim: Data from SAP is in label form like 11.06.06 and I would like to convert
them to data to berecognized by Excel in date format.

The macro recorded is:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 9/19/2006 by Annamalai
'
' Keyboard Shortcut: Ctrl+z
'
ActiveCell.FormulaR1C1 = "11-Sep-2006"
Range("F10").Select
End Sub

Data used:
11-Sep-06
11-Sep-06
22.05.06
11-Sep-06
Top cell was manually edited and macro recorded. Bottom 2&4 were the result
after macro use(first cell repeats). Cell 3, is raw data, waiting conversion.

Annamalai
xxxxxxxxxxxxxxxxxxxxx

"Stefi" wrote:

Post your macro!
Stefi


€˛Annamalai€¯ ezt Ć*rta:

I use macros by recording, not familiar with Visual Basics. I want to edit
the cell content of similar cells . When I run the macro on other cells it
takes the information from the very first cell and keeps repeating the info
on the first cell. What is wrong?
Is there any Excel short cut like Lotus 123, macro "?" to represent to "hold
and fill" while the macro is running.