Transpose with dates problem - from the dd/mm/yy to mm/dd/yyyy

pcardenasm

New Member
Joined
Oct 28, 2023
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi,

I need some help again, I have a problem when I transpose a date range, some dates are changed from the dd/mm/yy to mm/dd/yyyy.

Puntos-registro.xlsm
ABCDEFGHIJKLMNOPQRSTUV
1Punto07/03/201713/03/201720/03/201727/03/201703/04/201712/04/201718/04/201725/04/201702/05/201708/05/201715/05/201722/05/201729/05/201705/06/201712/06/201719/06/201728/06/201703/07/201714/07/201721/07/201724/07/2017
2230.042.027.027.026.027.027.026.027.029.030.032.039.034.030.033.031.025.029.031.032.0
3325.042.054.024.018.034.050.052.025.055.034.053.024.025.047.029.025.060.027.071.061.0
4413.939.953.924.917.934.949.951.926.953.934.952.923.923.944.928.924.958.927.970.958.9
5531.240.228.228.225.233.227.225.228.228.230.234.234.240.228.230.229.223.229.232.233.2
6815.635.635.623.616.629.634.635.624.644.628.644.621.623.633.624.622.636.620.635.634.6
79-1.42.61.6-1.4-2.4-5.4-7.4-9.4-4.4-3.4-3.4-3.4-5.4-5.4-7.4-8.4-5.4-9.4-16.4-18.4-18.4
81015.035.035.025.017.030.035.035.026.045.019.044.012.024.034.014.015.036.023.034.035.0
911-3.5-20.5-23.5-18.5-19.5-14.5-11.5-8.54.58.56.5-4.5-11.5-12.5-16.5-21.5-24.5-22.5-11.5-19.5-14.5
1012-2.935.136.125.119.131.135.134.126.144.129.138.123.124.132.126.125.135.122.135.135.1
1113-3.410.60.6-2.45.64.63.69.626.634.625.634.6-2.4-0.44.6-0.4-1.43.6-1.43.60.6
121432.145.126.125.125.126.127.128.127.139.130.154.132.135.140.135.135.141.135.142.141.1
131530.137.124.125.124.126.126.125.127.128.129.132.1-3.9-3.9-3.9-3.9-3.9-3.9-3.9-3.9-3.9
1416-3.2-0.2-1.2-3.2-7.22.82.88.824.833.824.836.8-3.2-1.20.8-1.2-2.22.8-2.22.8-1.2
1517-23.5-21.5-25.5-23.5-21.5-16.5-12.5-9.52.57.55.5-7.5-12.5-13.5-21.5-23.5-29.5-26.5-12.5-21.5-15.5
1618-1.61.40.4-1.6-4.6-7.6-7.6-10.6-4.6-1.6-2.6-4.6-6.6-5.6-7.6-10.6-6.6-10.6-17.6-20.6-20.6
1719-31.4-31.4-34.4-35.4-35.4-38.4-41.4-42.4-39.4-41.4-40.4-35.4-35.4-34.4-36.4-37.4-38.4-38.4-35.4-35.4-37.4
1820-38.8-34.8-38.8-38.8-39.8-38.8-38.8-38.8-38.8-38.8-41.8-38.8-41.8-39.8-28.8-37.8-37.8-37.8-38.8-36.8-38.8
1921-7.1-5.1-11.1-11.1-11.1-8.1-9.1-9.1-7.1-12.1-12.1-9.1-13.1-9.1-11.1-11.1-12.1-9.1-12.1-11.1-11.1
2022-8.5-18.5-22.5-12.5-21.5-10.5-10.5-11.5-7.5-23.5-13.5-11.5-13.5-10.5-11.5-12.5-13.5-10.5-10.5-12.5-13.5
2123-42.8-38.8-43.8-39.8-42.8-48.8-40.8-41.8-43.8-44.8-44.8-40.8-46.8-40.8-40.8-44.8-44.8-39.8-46.8-46.8-40.8
2224-44.3-35.3-44.3-40.3-44.3-52.3-42.3-44.3-44.3-44.3-47.3-44.3-45.3-45.3-46.3-45.3-45.3-45.3-45.3-39.3-42.3
2325-43.9-39.9-43.9-38.9-43.9-49.9-41.9-42.9-45.9-45.9-45.9-43.9-46.9-41.9-40.9-44.9-44.9-40.9-44.9-43.9-41.9
2426-42.8-35.8-41.8-40.8-42.8-43.8-43.8-43.8-43.8-43.8-38.8-41.8-41.8-41.8-43.8-43.8-43.8-41.8-40.8-40.8-42.8
2527-45.6-38.6-45.6-40.6-45.6-46.6-41.6-43.6-46.6-45.6-46.6-43.6-47.6-41.6-41.6-41.6-40.6-40.6-45.6-43.6-42.6
2628-44.2-41.2-45.2-40.2-44.2-50.2-41.2-42.2-45.2-44.2-46.2-42.2-48.2-43.2-42.2-46.2-45.2-41.2-48.2-46.2-41.2
2729-45.8-42.8-44.8-40.8-44.8-49.8-42.8-42.8-46.8-43.8-46.8-43.8-47.8-44.8-42.8-46.8-45.8-42.8-48.8-47.8-41.8
2830-44.7-40.7-45.7-49.7-43.7-50.7-40.7-42.7-45.7-44.7-45.758.3-46.7-43.7-41.7-45.7-44.7-40.7-46.7-46.7-40.7
2932-44.4-41.4-44.4-39.4-34.4-50.4-41.4-42.4-46.4-45.4-46.4-42.4-47.4-45.4-42.4-45.4-46.4-41.4-47.4-47.4-42.4
3033-44.5-42.5-44.5-39.5-43.5-48.5-42.5-42.5-45.5-43.5-44.5-42.5-47.5-45.5-41.5-45.5-44.5-41.5-48.5-47.5-41.5
313432.136.127.127.127.128.128.127.127.130.131.130.131.134.127.129.131.125.129.132.133.1
3235-45.3-43.3-45.3-40.3-44.3-51.3-41.3-42.3-45.3-44.3-46.3-42.3-48.3-44.3-42.3-46.3-48.3-40.3-48.3-47.3-41.3
3336-44.3-43.3-43.3-38.3-42.3-47.3-40.3-41.3-42.3-42.3-44.3-36.3-45.3-42.3-40.3-45.3-44.3-40.3-45.3-44.3-40.3
3438121.0148.0159.0131.0126.0143.0156.0159.0133.0160.0116.0156.0131.0132.0154.0136.0133.0167.0134.0176.0163.0
SeguimientoAbs



I wrote a code to order by dates and point of registry:


VBA Code:
Sub TransposeRange()
    Dim Lastcolumn As Variant
    Dim LastRowNiv As Variant
    Dim LastRow As Variant
    Dim MyRange As Variant
    Dim firstRow As Long
    Dim numfilas As Variant
    Dim RangoNiv As Variant
    Dim RangoPuntos As Variant
    Dim element As Variant
    Dim numcolumns As Integer
    Dim k As Variant
    Dim numcolumndatos As Variant
    Dim numfilasdatos As Variant
    Dim k1 As Variant
    
    Application.ScreenUpdating = False
    firstRow = 2
    LastRow = Sheets("PorPuntos").Range("A" & Rows.Count).End(xlUp).Row
    If LastRow < 2 Then LastRow = 2
    Sheets("PorPuntos").Range("A2:C" & LastRow).ClearContents
    Lastcolumn = Sheets("SeguimientoAbs").Cells(1, Columns.Count).End(xlToLeft).Column
    LastRowNiv = Sheets("SeguimientoAbs").Range("A" & Rows.Count).End(xlUp).Row
    
    
    
    PuntosArray = Array(2, 3, 4, 5, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 38)
    
    For Each element In PuntosArray
    

    
    MyRange = Sheets("SeguimientoAbs").Range(Cells(1, 2).Address, Cells(1, Lastcolumn).Address)
        'find dimensions of range
        XUpper = UBound(MyRange, 1)
        XLower = LBound(MyRange, 1)
        YUpper = UBound(MyRange, 2)
        YLower = LBound(MyRange, 2)
    
        'transpose range

        Sheets("PorPuntos").Range("A" & firstRow).Resize(YUpper - YLower + 1, XUpper - XLower + 1).Value = _
        Application.Transpose(MyRange)
        
        LastRow = Sheets("PorPuntos").Range("A" & Rows.Count).End(xlUp).Row
        RangoNiv = Sheets("SeguimientoAbs").Range(Cells(2, 2).Address, Cells(LastRowNiv, Lastcolumn).Address)
        RangoPuntos = Sheets("SeguimientoAbs").Range(Cells(2, 1).Address, Cells(LastRowNiv, 1).Address)
        
            For numfilas = firstRow To LastRow
                numfilasdatos = numfilas - 1
                numcolumndatos = Lastcolumn - 1
                If numfilas <= Lastcolumn Then
                        numcolumns = numfilas - 1
                
                    ElseIf numfilasdatos Mod numcolumndatos = 0 Then
                        numcolumns = Lastcolumn - 1
                    
                        ElseIf numfilas > Lastcolumn Then
                            numcolumns = numfilasdatos - WorksheetFunction.RoundDown(numfilasdatos / numcolumndatos, 0) * numcolumndatos

                        
                End If
                
                Sheets("PorPuntos").Cells(numfilas, 2) = element
                
                k = Application.WorksheetFunction.Index(RangoNiv, Application.WorksheetFunction.Match(element, RangoPuntos, 0), numcolumns)

                If IsEmpty(k) Then
                    k1 = ""
                Else
                    k1 = k
                End If

                Sheets("PorPuntos").Cells(numfilas, 3) = k1

            Next numfilas
        
        firstRow = LastRow + 1
        Application.CutCopyMode = False

        Next element
    
    Application.ScreenUpdating = True
    Sheets("PorPuntos").Select
    Range("B2").Select
    MsgBox "Valores copiados exitosamente", vbInformation, "Copiar"
    

      
End Sub


But I have some errors in some dates

Puntos-registro.xlsm
ABC
1FechaPuntoNivel (Abs)
203/07/2017230.0
313/03/2017242.0
420/03/2017227.0
527/03/2017227.0
604/03/2017226.0
704/12/2017227.0
818/04/2017227.0
925/04/2017226.0
1005/02/2017227.0
1105/08/2017229.0
1215/05/2017230.0
1322/05/2017232.0
1429/05/2017239.0
1506/05/2017234.0
1606/12/2017230.0
1719/06/2017233.0
1828/06/2017231.0
1907/03/2017225.0
2014/07/2017229.0
2121/07/2017231.0
2224/07/2017232.0
2324/08/2017230.0
2430/08/2017239.0
2509/04/2017233.0
2609/11/2017233.0
2718/09/2017231.0
2825/09/2017229.0
2910/02/2017229.0
PorPuntos


File-xlsm

I hope you can help me. Thank you

Patricia CM
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Think the VBA issue is due to default date format but an alternative solution is PQ
This can be done in Power query very easily
Book1
ABC
1FechaPuntoNivel (Abs)
207/03/2017230
313/03/2017242
420/03/2017227
527/03/2017227
603/04/2017226
712/04/2017227
818/04/2017227
925/04/2017226
1002/05/2017227
1108/05/2017229
1215/05/2017230
1322/05/2017232
1429/05/2017239
1505/06/2017234
1612/06/2017230
1719/06/2017233
1828/06/2017231
1903/07/2017225
2014/07/2017229
2121/07/2017231
2224/07/2017232
2307/03/2017325
2413/03/2017342
2520/03/2017354
2627/03/2017324
Table1



Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Punto", Int64.Type}, {"07/03/2017", type number}, {"13/03/2017", type number}, {"20/03/2017", type number}, {"27/03/2017", type number}, {"03/04/2017", type number}, {"12/04/2017", type number}, {"18/04/2017", type number}, {"25/04/2017", type number}, {"02/05/2017", type number}, {"08/05/2017", type number}, {"15/05/2017", type number}, {"22/05/2017", type number}, {"29/05/2017", type number}, {"05/06/2017", type number}, {"12/06/2017", type number}, {"19/06/2017", type number}, {"28/06/2017", type number}, {"03/07/2017", type number}, {"14/07/2017", type number}, {"21/07/2017", type number}, {"24/07/2017", type number}}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"Punto"}, "Attribute", "Value"),
    #"Reordered Columns" = Table.ReorderColumns(#"Unpivoted Other Columns",{"Attribute", "Punto", "Value"}),
    #"Renamed Columns" = Table.RenameColumns(#"Reordered Columns",{{"Attribute", "Fecha"}, {"Value", "Nivel (Abs)"}})
in
    #"Renamed Columns"
 
Upvote 0
Try changing this line to be Value2 (add the 2 on the end)

Rich (BB code):
    MyRange = Sheets("SeguimientoAbs").Range(Cells(1, 2).Address, Cells(1, Lastcolumn).Address).Value2
 
Upvote 0
Solution

Forum statistics

Threads
1,215,083
Messages
6,123,020
Members
449,092
Latest member
ikke

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