gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
I have data in column B that starts from B18. All the data starts with a text date in…
- User
I have data in column B that starts from B18. All the data starts with a text date in the format dd/mm/yyyy I would like to sort the range by the text date format with the oldest dat at the top. Can you please write a VBA code to do this
- Assistant
Sure! Here's a VBA code that sorts the data in column B (starting from B18) in ascending order based on the text date format (dd/mm/yyyy):
Sub SortData() Dim ws As Worksheet Dim lastRow As Long ' Set the worksheet to modify Set ws = ThisWorkbook.Sheets("Sheet1") ' Replace "Sheet1" with your sheet name ' Find the last row with data in column B lastRow = ws.Cells(ws.Rows.Count, "B").End(xlUp).Row ' Sort the data in ascending order based on the text date format With ws.Sort .SortFields.Clear .SortFields.Add Key:=Range("B18:B" & lastRow), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers .SetRange Range("B18:B" & lastRow) .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With ' Clean up Sort object Set ws = Nothing End SubMake sure to replace "Sheet1" with the name of your sheet or update the code accordingly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.