Code for ascending dates

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a worksheet that copies to another sheet successfully but I want to add in the code for it to sort the dates in column A so it is in ascending order. The code I am using to sort that column gives me this error https://www.screencast.com/t/PfhLFOtFxR7 and the code is
Code:
Worksheets(combo).Range("A4:A1000").Sort Key1:=Range("A4:A1000"), Order1:=xlAscending

Combo is a variable that changes depending on the date and I have it successfully transferring into the correct sheet without the sort code. What code should I be using?
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
There is about 3 columns of data next to the date that will need to be sorted with the dates.
 
Upvote 0
To begin with, the sheets are monthly so there will be no data in a sheet for the month.
 
Upvote 0
This is the code I got from the macro recorder:
Code:
   ActiveWorkbook.Worksheets("August 2018").ListObjects("August18").Sort. _
        SortFields.Clear
    ActiveWorkbook.Worksheets("August 2018").ListObjects("August18").Sort. _
        SortFields.Add2 Key:=Range("August18[[#All],[Date of work]]"), SortOn:= _
        xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("August 2018").ListObjects("August18").Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With

That was just using one of my sheets ("August18") but I have a variable called combo that is set to a cell that makes of fields to arrive at the correct month to enter the costing into relative to the date on the costing. Should I just replace all the occurrences of "August18" with combo as that doesn't seem to work.
 
Upvote 0

Forum statistics

Threads
1,215,309
Messages
6,124,180
Members
449,146
Latest member
el_gazar

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