Date function

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this code and not sure as what is wrong, it is not giving me the required result, any help

in row no 8 have this date

11/01/23, 00:0012/01/23, 00:0013/01/23, 00:0001/02/23, 00:0002/02/23, 00:0003/02/23, 00:00
Result11/01/2312/01/2313/01/2301/02/2302/02/2303/02/23
11-Jan12-Jan13-Jan1-Feb2-Feb3-Feb





VBA Code:
Sub TO_DATE1()
    Range("R2").Select
    Selection.Formula = "=IF(R8="""","""",IF(OR(R8=""NE_STATE"",R8=""Short name"",R8=""OLT""),"""",R8))"
    Selection.Copy
    Range("R2").Select
'    Range(Selection, Selection.End(xlToRight)).Select
    Range("R2:LZ2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

'On Error Resume Next

Dim e As Range, te As String
For Each e In Range("R2:LZ2")
    te = e.Value
    If Mid(te, 2, 1) = "/" Then te = "0" & te
    If Len(te) > 7 Then e = CDate(Left(te, 8))
Next
Range("R2:LZ2").NumberFormat = "dd/mm/yy"
End Sub

 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
I have this code and not sure as what is wrong, it is not giving me the required result, any help

in row no 8 have this date

11/01/23, 00:0012/01/23, 00:0013/01/23, 00:0001/02/23, 00:0002/02/23, 00:0003/02/23, 00:00
Result11/01/2312/01/2313/01/2301/02/2302/02/2303/02/23
11-Jan12-Jan13-Jan1-Feb2-Feb3-Feb





VBA Code:
Sub TO_DATE1()
    Range("R2").Select
    Selection.Formula = "=IF(R8="""","""",IF(OR(R8=""NE_STATE"",R8=""Short name"",R8=""OLT""),"""",R8))"
    Selection.Copy
    Range("R2").Select
'    Range(Selection, Selection.End(xlToRight)).Select
    Range("R2:LZ2").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

'On Error Resume Next

Dim e As Range, te As String
For Each e In Range("R2:LZ2")
    te = e.Value
    If Mid(te, 2, 1) = "/" Then te = "0" & te
    If Len(te) > 7 Then e = CDate(Left(te, 8))
Next
Range("R2:LZ2").NumberFormat = "dd/mm/yy"
End Sub

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.
 
Upvote 0
here you go,

Nokia VLAN Traffic IN Daily -V1.xlsm
XYZAAABACADAEAFAGAHAIAJAK
107/01/23, 00:0008/01/23, 00:0009/01/23, 00:0010/01/23, 00:0011/01/23, 00:0012/01/23, 00:0013/01/23, 00:0014/01/23, 00:0015/01/23, 00:0016/01/23, 00:0017/01/23, 00:0018/01/23, 00:0019/01/23, 00:0020/01/23, 00:00
201/07/202301/08/202301/09/202301/10/202301/11/202301/12/202323/01/201314/01/23, 00:0015/01/23, 00:0016/01/23, 00:0017/01/23, 00:0018/01/23, 00:0019/01/23, 00:0020/01/23, 00:00
3
4
5
6
7
807/01/23, 00:0008/01/23, 00:0009/01/23, 00:0010/01/23, 00:0011/01/23, 00:0012/01/23, 00:0013/01/23, 00:0014/01/23, 00:0015/01/23, 00:0016/01/23, 00:0017/01/23, 00:0018/01/23, 00:0019/01/23, 00:0020/01/23, 00:00
93.06845E+122.90603E+123.30355E+122.83128E+122.83665E+123.00948E+123.0468E+123.16649E+123.16175E+123.04794E+122.82622E+123.01735E+123.12863E+123.24451E+12
102.02025E+131.80057E+131.97399E+131.78594E+131.9489E+131.84219E+132.01856E+132.24439E+132.14328E+131.94547E+131.93774E+131.96367E+132.00135E+132.04886E+13
115.37341E+135.04525E+135.03153E+134.88383E+134.89635E+134.9587E+136.1265E+135.26875E+135.20574E+135.05483E+134.86879E+135.00431E+135.06816E+136.05485E+13
125.67331E+134.9213E+135.46853E+134.77041E+135.0679E+135.0201E+135.4412E+135.56879E+135.33331E+135.30923E+135.05004E+135.53005E+135.27154E+135.55282E+13
135.04924E+134.96107E+135.38011E+134.92973E+134.57306E+135.1556E+135.09729E+135.05169E+134.79752E+134.67954E+134.56062E+135.09003E+135.20419E+135.47822E+13
145.82176E+135.7111E+136.23844E+135.52229E+135.2813E+136.1053E+135.89999E+136.00321E+135.65849E+135.35906E+134.93561E+135.70421E+136.16078E+136.41756E+13
153.60144E+133.60809E+133.89735E+133.4635E+133.34112E+133.73852E+133.50358E+133.67278E+133.57901E+133.45482E+133.24343E+133.67637E+133.80834E+133.78083E+13
164.17636E+134.05771E+134.44509E+133.96323E+133.68347E+134.22796E+133.95644E+134.05234E+133.94942E+133.94978E+133.74776E+134.03046E+134.21159E+134.36659E+13
172.34576E+132.32089E+132.20241E+132.32954E+132.18373E+132.36615E+132.30809E+132.29219E+132.19041E+132.12124E+132.1561E+132.36366E+132.48126E+132.65468E+13
183.50704E+133.4919E+133.51274E+133.65808E+133.40239E+133.85869E+133.6565E+133.80887E+133.6803E+133.65089E+133.36128E+133.71624E+133.90888E+133.89198E+13
194.67637E+134.1764E+134.65392E+133.99217E+134.44107E+134.39842E+134.7237E+134.71981E+134.51594E+134.44681E+134.13172E+134.48871E+134.48841E+134.69083E+13
201.92632E+131.85455E+132.03177E+131.92304E+131.78454E+131.99801E+132.02395E+132.18437E+131.88662E+131.88191E+131.78905E+131.88314E+131.99079E+132.11501E+13
213.03128E+132.79463E+133.08E+132.69527E+132.69774E+132.87943E+133.05914E+132.96563E+133.05846E+132.8843E+132.65272E+132.89355E+132.89236E+133.16101E+13
222.21228E+131.8983E+131.96145E+131.76097E+132.03697E+131.96372E+132.0931E+132.3998E+132.32343E+132.08789E+132.11284E+131.98015E+132.07178E+132.23969E+13
231.8098E+131.76274E+131.94947E+131.82121E+131.75575E+131.90946E+131.89762E+131.86959E+131.7757E+131.67704E+131.65241E+131.79115E+131.79145E+131.96492E+13
Sheet1
Cell Formulas
RangeFormula
X1:AK1X1=IF(X8="","",IF(OR(X8="NE_STATE",X8="Short name",X8="OLT"),"",X8))
AE2:AK2AE2=IF(AE8="","",IF(OR(AE8="NE_STATE",AE8="Short name",AE8="OLT"),"",AE8))
 
Upvote 0
How about an exaplanation (in plain English) of exactly what it is that you are trying to do?
It is not obvious to me (and I suspect to others as well).
 
Upvote 0
How about an exaplanation (in plain English) of exactly what it is that you are trying to do?
It is not obvious to me (and I suspect to others as well).
I am trying to get the date in row 2 from row 8, using the script, but after executin the script its not giving me the correct resulit in row 2
the acutal date is dd/mm/yyyy, 00:00 in row 8
out put in row 2 sould be dd/mm/yyyy

I am sure now its clear, i have kept the table in my first post and sample data in my 2 post.
 
Upvote 0
I am assuming that your values in row 8 are entered as Text and not as Date (that is what the left-justification seems to indicate).

If that is so, then try this formula for cell X2:
Excel Formula:
=IF(X8="","",IF(OR(X8="NE_STATE",X8="Short name",X8="OLT"),"",DATE("20" & MID(X8,7,2),MID(X8,4,2),LEFT(X8,2))))
and be sure to format row to the custom date format of "dd/mm/yyyy".
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top