R
R.VENKATARAMAN
I am downloading a statement from the web. original statement was perhaps
not in excel spreadsheet format.But there is provision to save the
statement in excel spreadsheet. But the dates are ENTERED in Indian style
(also british style) i.e. date/month/year and not in excel entry mode.
the year is given as 2004 or 2003. I prepared an elaborate (perhaps not
very efficient) customisesd code for this. the part I below gives the logic
behind my code. part II gives the actual module consisting of three subs.
PART III gives sample data in the first column and the results after the vba
is run in the second column. The idea is to use excel procedures like sort,
filter, formatting etc.
apologise for the long message. what I would like to know is whether there
is any easier method without using a vba programme.
----------------------------------------------------------------------------
-----------------------------------
PART I
the original statement have many problems
1. If the date is <=12 it is in date format
I.e it is entered as m/d/y
but not as we want
12/6/03 is december 6 2003 but we want
12 june 2003. I have only to change month as date and date as month.
2.if the date is >12 it is general format. Then if you want to find
day(activecell) it is the last entry
in 25/7/03 it you type the formula
=day(activcell) it gives 3
and year(activecell) gives 2025
I have to convert day (i.e. 3) as year and add 2000. I have to convert year
as date and subtract 2000
3,. yet another conf;usion. if the date is 30 or 31
for e.g. 30/6/03
ok the day(activecell) gives 3 and I convert this to year and add 2000
but year(activecell) gives 1930(not 2030) and if I convert to date then I
have to subtract 1900
and not 200 as in the case 2 above.
4. yet another profblem the year is given as 2004 or 2003 etc. as in some
cases the year becomes dats finally this give problem so I have to replace
these into 04 or 03, after doing this I apply code <expt 4> in the code
given below.
PART II
----------------------------------------------------------------------------
-------------------------------------------
Option Explicit
Public Sub expt4()
Application.ScreenUpdating = False
Range("a1").Activate
Cells.Find(what:="Txn date").Activate
Dim myrange As Range
Set myrange = Range(ActiveCell.Offset(2, 0), ActiveCell.Offset(2,
0).End(xlDown))
Dim cell As Range
For Each cell In myrange
cell.Activate
If ActiveCell.NumberFormat = "m/d/yy" Then
expt3
Else
expt5
End If
ActiveCell.NumberFormat = "dd-mmm-yy"
Next
Application.ScreenUpdating = True
End Sub
======================================================
Public Sub expt5()
Dim d, m, y As Integer
If Year(ActiveCell) < 2000 Then
d = Year(ActiveCell) - 1900
Else
d = Year(ActiveCell) - 2000
End If
m = Month(ActiveCell)
y = Day(ActiveCell) + 2000
ActiveCell.Offset(0, 1).Activate
ActiveCell = m & "/" & d & "/" & y
End Sub
================================================================
Public Sub expt3()
'two types of format 1) if date is <12 it is in
'date formate 2) if date is >12 itis
'general format.
'this is for those cells in date format
Dim d, m, y As Integer
Dim mo As String
d = Month(ActiveCell)
m = Day(ActiveCell)
y = Year(ActiveCell)
'mo = MonthName(m)
ActiveCell.Offset(0, 1).Activate
ActiveCell.NumberFormat = "general"
ActiveCell = m & "/" & d & "/" & y
End Sub
----------------------------------------------------------------------------
-----------
PART III
the first column is data as received, second column the result after the
code is run.
Txn Date
(empty row)
14/06/2004 14-Jun-04
29/06/2004 29-Jun-04
3/7/202004 03-Jul-04
9/7/202004 09-Jul-04
19/07/2004 19-Jul-04
21/07/2004 21-Jul-04
23/07/2004 23-Jul-04
26/07/2004 26-Jul-04
27/07/2004 27-Jul-04
28/07/2004 28-Jul-04
29/07/2004 29-Jul-04
7/8/202004 07-Aug-04
not in excel spreadsheet format.But there is provision to save the
statement in excel spreadsheet. But the dates are ENTERED in Indian style
(also british style) i.e. date/month/year and not in excel entry mode.
the year is given as 2004 or 2003. I prepared an elaborate (perhaps not
very efficient) customisesd code for this. the part I below gives the logic
behind my code. part II gives the actual module consisting of three subs.
PART III gives sample data in the first column and the results after the vba
is run in the second column. The idea is to use excel procedures like sort,
filter, formatting etc.
apologise for the long message. what I would like to know is whether there
is any easier method without using a vba programme.
----------------------------------------------------------------------------
-----------------------------------
PART I
the original statement have many problems
1. If the date is <=12 it is in date format
I.e it is entered as m/d/y
but not as we want
12/6/03 is december 6 2003 but we want
12 june 2003. I have only to change month as date and date as month.
2.if the date is >12 it is general format. Then if you want to find
day(activecell) it is the last entry
in 25/7/03 it you type the formula
=day(activcell) it gives 3
and year(activecell) gives 2025
I have to convert day (i.e. 3) as year and add 2000. I have to convert year
as date and subtract 2000
3,. yet another conf;usion. if the date is 30 or 31
for e.g. 30/6/03
ok the day(activecell) gives 3 and I convert this to year and add 2000
but year(activecell) gives 1930(not 2030) and if I convert to date then I
have to subtract 1900
and not 200 as in the case 2 above.
4. yet another profblem the year is given as 2004 or 2003 etc. as in some
cases the year becomes dats finally this give problem so I have to replace
these into 04 or 03, after doing this I apply code <expt 4> in the code
given below.
PART II
----------------------------------------------------------------------------
-------------------------------------------
Option Explicit
Public Sub expt4()
Application.ScreenUpdating = False
Range("a1").Activate
Cells.Find(what:="Txn date").Activate
Dim myrange As Range
Set myrange = Range(ActiveCell.Offset(2, 0), ActiveCell.Offset(2,
0).End(xlDown))
Dim cell As Range
For Each cell In myrange
cell.Activate
If ActiveCell.NumberFormat = "m/d/yy" Then
expt3
Else
expt5
End If
ActiveCell.NumberFormat = "dd-mmm-yy"
Next
Application.ScreenUpdating = True
End Sub
======================================================
Public Sub expt5()
Dim d, m, y As Integer
If Year(ActiveCell) < 2000 Then
d = Year(ActiveCell) - 1900
Else
d = Year(ActiveCell) - 2000
End If
m = Month(ActiveCell)
y = Day(ActiveCell) + 2000
ActiveCell.Offset(0, 1).Activate
ActiveCell = m & "/" & d & "/" & y
End Sub
================================================================
Public Sub expt3()
'two types of format 1) if date is <12 it is in
'date formate 2) if date is >12 itis
'general format.
'this is for those cells in date format
Dim d, m, y As Integer
Dim mo As String
d = Month(ActiveCell)
m = Day(ActiveCell)
y = Year(ActiveCell)
'mo = MonthName(m)
ActiveCell.Offset(0, 1).Activate
ActiveCell.NumberFormat = "general"
ActiveCell = m & "/" & d & "/" & y
End Sub
----------------------------------------------------------------------------
-----------
PART III
the first column is data as received, second column the result after the
code is run.
Txn Date
(empty row)
14/06/2004 14-Jun-04
29/06/2004 29-Jun-04
3/7/202004 03-Jul-04
9/7/202004 09-Jul-04
19/07/2004 19-Jul-04
21/07/2004 21-Jul-04
23/07/2004 23-Jul-04
26/07/2004 26-Jul-04
27/07/2004 27-Jul-04
28/07/2004 28-Jul-04
29/07/2004 29-Jul-04
7/8/202004 07-Aug-04