Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Convert Date Stored as Text with VBA in many Workbooks

Hello All,
I am using Windows XP/Office 2003
I have many workbooks stored in C:\Temp
All these work books have date stored in mixed format in two columns
viz Column A and Column D as follows:


12/31/06 ---- stored as text
13/1/06
15/1/06
1/16/06 ---- stored as text
17/1/06
20/1/06


As can be seen from above data sample the dates are stored in mixed
format.

I have run the following macro which works for Column A only (for
Column D I need to change the Range every time and there are many
workbooks so it is very time consuming process

Sub test()
With ActiveSheet.Range("A1:A100")
..NumberFormat = "dd/mm/yyyy"
..Value = .Value
End With
End Sub

My requirement is to have a macro to open all the workbooks one after
another in Folder C:\Temp and run the macro on Sheet1 in Columns A and
D and convert the dates stored in mixed format to proper date format

Can this be achieved?

Thanks in advance

Rashid Khan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Convert Date Stored as Text with VBA in many Workbooks

Sub test()
Dim sName as String
Dim sPath as String
Dim bk as Workbook
Dim rngA as Range, rngB as Range
sPath = "C:\Temp\"
sname = Dir(sPath & "*.xls")
do while sName < ""
set bk = Workbooks.Open(sPath & sName)
With bk.worksheets(1)
set rngA = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
set rngD = .Range(.Cells(1,4),.Cells(rows.count,4).End(xlup))
End with
With rngA
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
With rngD
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End with
bk.Close SaveChanges:=True
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hello All,
I am using Windows XP/Office 2003
I have many workbooks stored in C:\Temp
All these work books have date stored in mixed format in two columns
viz Column A and Column D as follows:


12/31/06 ---- stored as text
13/1/06
15/1/06
1/16/06 ---- stored as text
17/1/06
20/1/06


As can be seen from above data sample the dates are stored in mixed
format.

I have run the following macro which works for Column A only (for
Column D I need to change the Range every time and there are many
workbooks so it is very time consuming process

Sub test()
With ActiveSheet.Range("A1:A100")
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
End Sub

My requirement is to have a macro to open all the workbooks one after
another in Folder C:\Temp and run the macro on Sheet1 in Columns A and
D and convert the dates stored in mixed format to proper date format

Can this be achieved?

Thanks in advance

Rashid Khan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Convert Date Stored as Text with VBA in many Workbooks

One small change to Tom's code, change this line:
Dim rngA as Range, rngB as Range
to
Dim rngA as Range, rngD as Range

Mike F
"Tom Ogilvy" wrote in message
...
Sub test()
Dim sName as String
Dim sPath as String
Dim bk as Workbook
Dim rngA as Range, rngB as Range
sPath = "C:\Temp\"
sname = Dir(sPath & "*.xls")
do while sName < ""
set bk = Workbooks.Open(sPath & sName)
With bk.worksheets(1)
set rngA = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
set rngD = .Range(.Cells(1,4),.Cells(rows.count,4).End(xlup))
End with
With rngA
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
With rngD
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End with
bk.Close SaveChanges:=True
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy


wrote in message
oups.com...
Hello All,
I am using Windows XP/Office 2003
I have many workbooks stored in C:\Temp
All these work books have date stored in mixed format in two columns
viz Column A and Column D as follows:


12/31/06 ---- stored as text
13/1/06
15/1/06
1/16/06 ---- stored as text
17/1/06
20/1/06


As can be seen from above data sample the dates are stored in mixed
format.

I have run the following macro which works for Column A only (for
Column D I need to change the Range every time and there are many
workbooks so it is very time consuming process

Sub test()
With ActiveSheet.Range("A1:A100")
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
End Sub

My requirement is to have a macro to open all the workbooks one after
another in Folder C:\Temp and run the macro on Sheet1 in Columns A and
D and convert the dates stored in mixed format to proper date format

Can this be achieved?

Thanks in advance

Rashid Khan





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Convert Date Stored as Text with VBA in many Workbooks

On Feb 11, 1:25 am, "Tom Ogilvy" wrote:
Sub test()
Dim sName as String
Dim sPath as String
Dim bk as Workbook
Dim rngA as Range, rngB as Range
sPath = "C:\Temp\"
sname = Dir(sPath & "*.xls")
do while sName < ""
set bk = Workbooks.Open(sPath & sName)
With bk.worksheets(1)
set rngA = .Range(.Cells(1,1),.Cells(rows.count,1).End(xlup))
set rngD = .Range(.Cells(1,4),.Cells(rows.count,4).End(xlup))
End with
With rngA
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
With rngD
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End with
bk.Close SaveChanges:=True
sName = dir()
Loop
End Sub

--
Regards,
Tom Ogilvy

wrote in message

oups.com...



Hello All,
I am using Windows XP/Office 2003
I have many workbooks stored in C:\Temp
All these work books have date stored in mixed format in two columns
viz Column A and Column D as follows:


12/31/06 ---- stored as text
13/1/06
15/1/06
1/16/06 ---- stored as text
17/1/06
20/1/06


As can be seen from above data sample the dates are stored in mixed
format.


I have run the following macro which works for Column A only (for
Column D I need to change the Range every time and there are many
workbooks so it is very time consuming process


Sub test()
With ActiveSheet.Range("A1:A100")
.NumberFormat = "dd/mm/yyyy"
.Value = .Value
End With
End Sub


My requirement is to have a macro to open all the workbooks one after
another in Folder C:\Temp and run the macro on Sheet1 in Columns A and
D and convert the dates stored in mixed format to proper date format


Can this be achieved?


Thanks in advance


RashidKhan- Hide quoted text -


- Show quoted text -


Thanks Tom
Works great.....you are a great help always.
Also thanks to Mike for pointing out the typo.


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
Convert dates stored as text Emece Excel Discussion (Misc queries) 2 May 22nd 10 06:37 AM
Need help converting Number stored as Text to Date LuvHaleiwa Excel Discussion (Misc queries) 4 December 21st 07 08:09 PM
convert value stored as text to logical refrence value! Remote Desktop Connection hotkey Excel Worksheet Functions 2 August 1st 05 01:56 PM
how do i convert a number stored as text to a numb in a vba loop bobm Excel Programming 3 June 21st 05 12:59 AM
Date stored as Text Andibevan Excel Discussion (Misc queries) 3 May 27th 05 03:37 PM


All times are GMT +1. The time now is 02:59 AM.

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

About Us

"It's about Microsoft Excel"