VBA Read dates

Andyb2

New Member
Joined
Jan 24, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have created a macro below using the recording function.

A) My macro code is quite long and I wanted to shorten it if possible, the main thing is when I highlight all the column to then make the table takes up lots of space?
B) I would like to convert the financial year dates as listed below to ordinary year dates. For example, in column AM I would like it to display (2018 04 as December 2018) and (2019 03 as 2019). The year and period are listed in column Q and R. However, i'm not sure the code to add, please can you help.

  • 2018 04 – December 2018
  • 2018 05 – January 2019
  • 2018 06 – February 2019
  • 2018 07 – March 2019
  • 2018 08 – April 2019
  • 2018 10 – May 2019
  • 2018 11- June 2019
  • 2018 12- July 2019
  • 2019 01 – August 2019
  • 2019 02 – September 2019
  • 2019 03 – October 2019
  • 2019 04 – November 2019
  • 2019 05 – December 2019
  • 2019 06 – January 2020

VBA Code:
Sub Andy_New_Macro_2()

'

' Andy_New_Macro_2 Macro

'



'

Sheets("_Keywords").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Customer Funder Account Mapping").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Exchange Rate Query RMID - King").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("RESPROJ Budget Load Summary").Select

ActiveWindow.SelectedSheets.Visible = False

ActiveWindow.ScrollWorkbookTabs Sheets:=-1

ActiveWindow.ScrollWorkbookTabs Sheets:=-1

Sheets("RESPROJ Budget Load Check").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Standard Browser Enquiry POST A").Select

Columns("A:A").Select

Selection.Delete Shift:=xlToLeft

Rows("1:1").Select

Selection.Delete Shift:=xlUp

Range("B8").Select

Application.CutCopyMode = False

ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A:$AL"), , xlYes).Name = _

"Table1"

Columns("A:AL").Select

ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1"

ActiveWindow.ScrollColumn = 28

ActiveWindow.ScrollColumn = 27

ActiveWindow.ScrollColumn = 26

ActiveWindow.ScrollColumn = 25

ActiveWindow.ScrollColumn = 24

ActiveWindow.ScrollColumn = 23

ActiveWindow.ScrollColumn = 22

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 15

ActiveWindow.ScrollColumn = 14

ActiveWindow.ScrollColumn = 13

ActiveWindow.ScrollColumn = 12

ActiveWindow.ScrollColumn = 11

ActiveWindow.ScrollColumn = 10

ActiveWindow.ScrollColumn = 11

ActiveWindow.ScrollColumn = 12

ActiveWindow.ScrollColumn = 13

ActiveWindow.ScrollColumn = 14

ActiveWindow.ScrollColumn = 15

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 22

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 15

Range("R4").Select

ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort.SortFields.Clear

ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort.SortFields.Add2 Key:=Columns("R:R"), SortOn:=xlSortOnValues _

, Order:=xlAscending, DataOption:=xlSortNormal

With ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

Sheets("Standard Browser Enquiry POST A").Select

Sheets("Standard Browser Enquiry POST A").Name = "R03 Transactions"

Sheets("Summary").Select

Sheets("Summary").Name = "R05 Summary"

Range("D12").Select

Sheets("R03 Transactions").Select

Columns("O:O").ColumnWidth = 19.47

Columns("O:O").ColumnWidth = 29.07

Columns("O:O").ColumnWidth = 36.4
 

Attachments

  • Picture2.jpg
    Picture2.jpg
    74.9 KB · Views: 8

maabadi

Well-known Member
Joined
Oct 22, 2012
Messages
1,809
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
When you Run macro, your selected sheet should be the sheet you want macro run on it.
 

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)

Andyb2

New Member
Joined
Jan 24, 2021
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Thanks, it works when I run the macros separately, rather than together. So that's a solution.

How can I add more than one macro button to my workbook, one button for each macro? When I try to add another the option is greyed out on my workbook. (see screenshot)
Picture of macro .jpg


VBA Code:
Sub Andy_New_Macro_2()

'

' Andy_New_Macro_2 Macro

'



'

Sheets("_Keywords").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Customer Funder Account Mapping").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Exchange Rate Query RMID - King").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("RESPROJ Budget Load Summary").Select

ActiveWindow.SelectedSheets.Visible = False

ActiveWindow.ScrollWorkbookTabs Sheets:=-1

ActiveWindow.ScrollWorkbookTabs Sheets:=-1

Sheets("RESPROJ Budget Load Check").Select

ActiveWindow.SelectedSheets.Visible = False

Sheets("Standard Browser Enquiry POST A").Select

Columns("A:A").Select

Selection.Delete Shift:=xlToLeft

Rows("1:1").Select

Selection.Delete Shift:=xlUp

Range("B8").Select

Application.CutCopyMode = False

ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A:$AL"), , xlYes).Name = _

"Table1"

Columns("A:AL").Select

ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight1"

ActiveWindow.ScrollColumn = 28

ActiveWindow.ScrollColumn = 27

ActiveWindow.ScrollColumn = 26

ActiveWindow.ScrollColumn = 25

ActiveWindow.ScrollColumn = 24

ActiveWindow.ScrollColumn = 23

ActiveWindow.ScrollColumn = 22

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 15

ActiveWindow.ScrollColumn = 14

ActiveWindow.ScrollColumn = 13

ActiveWindow.ScrollColumn = 12

ActiveWindow.ScrollColumn = 11

ActiveWindow.ScrollColumn = 10

ActiveWindow.ScrollColumn = 11

ActiveWindow.ScrollColumn = 12

ActiveWindow.ScrollColumn = 13

ActiveWindow.ScrollColumn = 14

ActiveWindow.ScrollColumn = 15

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 22

ActiveWindow.ScrollColumn = 21

ActiveWindow.ScrollColumn = 20

ActiveWindow.ScrollColumn = 19

ActiveWindow.ScrollColumn = 18

ActiveWindow.ScrollColumn = 17

ActiveWindow.ScrollColumn = 16

ActiveWindow.ScrollColumn = 15

Range("R4").Select

ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort.SortFields.Clear

ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort.SortFields.Add2 Key:=Columns("R:R"), SortOn:=xlSortOnValues _

, Order:=xlAscending, DataOption:=xlSortNormal

With ActiveWorkbook.Worksheets("Standard Browser Enquiry POST A").ListObjects( _

"Table1").Sort

.Header = xlYes

.MatchCase = False

.Orientation = xlTopToBottom

.SortMethod = xlPinYin

.Apply

End With

Sheets("Standard Browser Enquiry POST A").Select

Sheets("Standard Browser Enquiry POST A").Name = "R03 Transactions"

Sheets("Summary").Select

Sheets("Summary").Name = "R05 Summary"

Range("D12").Select

Sheets("R03 Transactions").Select

Columns("O:O").ColumnWidth = 19.47

Columns("O:O").ColumnWidth = 29.07

Columns("O:O").ColumnWidth = 36.4

End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,803
Members
416,983
Latest member
LessThanAverageUser

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
Top