Macro problem for any workbook

steve6501

Board Regular
Joined
Jun 18, 2004
Messages
89
Hello

I have shown part of a macro which I recorded which works fine assuming the file is named "bank_analysis_20130417"

What I want is to be able to do the same personal macro to open a file for each day ie 18/04, 19/04 etc etc without having to change the date within the macro each time. I have tried removing the date with no success.

Sub Prepfile()
Columns("D:D").EntireColumn.AutoFit
Columns("D:D").Select
ActiveWorkbook.Worksheets("bank_analysis_20130417").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("bank_analysis_20130417").Sort.SortFields.Add Key:= _
Range("B1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("bank_analysis_20130417").Sort
.SetRange Range("A2:AB6122")

The macro continues with several more operations to prepare the file use

Am I able to do this please?

Steve
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
couldn't edit my last post

Code:
 Sub Prepfile()
TDate = Format(Date, "yyyymmdd")
Columns("D:D").EntireColumn.AutoFit
Columns("D:D").Select
ActiveWorkbook.Worksheets("bank_analysis_" & TDate).Sort.SortFields.Clear
ActiveWorkbook.Worksheets("bank_analysis_" & TDate).Sort.SortFields.Add Key:= _
Range("B1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("bank_analysis_" & TDate).Sort
.SetRange Range("A2:AB6122")
End Sub
 
Upvote 0

Forum statistics

Threads
1,207,091
Messages
6,076,522
Members
446,212
Latest member
KJAYPAL200

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