I am a new to VBA.
I will have many sheets in a workbook, for 300+ projects, and I wish to create a macro that is run when a project sheet is opened.
Each sheet in Row 4 has the months from 2017 to 2031 (day 1 of the month is used) with 1 Jan 17 being in H4. Columns A to F are frozen.
On opening sheet I want the present month column selected (in say Row 19) so that, as seen on the screen, I see columns A to F then last month, then today's month followed by later months. May 25 is column DD so the aim would be to see columns A to F and DB to DG
Each of these project sheets are frozen on G5, both above and to the left
I have been trying to do this, and failing!
Sub Macro3()
' Macro3 Move to Current Month column
Range("G6").Select
' To ensure that Column G is visible next to Column F
Cells(19, 110).Select
' For the columns To go Right so that the current month column can be seen (and, say, those of the 2 months before and 6 after - this does depend how wide the Excel window is.)
End Sub
This does work but the column number (110), which is Column DF, is hardcoded. I want it to automatically change as the months pass.
In another sheet in this workbook I have a way of generating this I have named this cell Screen_Column.
I have failed to find a way to introduce the value in Screen_Column into Cells(19, 110).Select
- with the 110 changing to 11? at the end of every month
I thought to do this
Dim COLU As Integer
Screen_Column = COLU
Range("G6").Select
Cells(19, COLU).Select
This did not work. Cannot get the value of Screen_Column to work in the Cells line
I am sure I have made a basic error and I know I may have missed a simple way of doing this but I have spent some time failing to find an answer.
I will be grateful for help and guidance. Thanks
Project, are they all sheets except a list, e.g.,[Sheet1,Sheet2], or something else? What exactly do you want to show and select for the current month? Is it columnsA:H,DB...and rows1:4,19...(or all rows) and selectDD19?