Guinaba
Board Regular
- Joined
- Sep 19, 2018
- Messages
- 217
- Office Version
- 2016
- Platform
- Windows
Hi guys,
I need to change the col. header from col.G to the last populated col. from first day of the week 01/06/2006 to Week Number/Year as shown below. Not sure why my code is not working. Any suggestion?
I need to change the col. header from col.G to the last populated col. from first day of the week 01/06/2006 to Week Number/Year as shown below. Not sure why my code is not working. Any suggestion?
Before running the code |
|
|
| |||
After running the code | 23/2020 | 24/2020 | 25/2020 |
VBA Code:
Dim LastCol As Integer
Dim Header As Variant
Dim i As Integer
'Starting counting from col. G and row 11
LastCol = Sheets("Report").cells(11, Columns.Count).End(xlToLeft).Column
Dim rng As Range: Set rng = Application.Range(cells(11, 7), cells(11, LastCol))
For i = 1 To rng.Columns.Count
Header = rng.cells(11, i).Value
Header = Sheets(1).Application.WorksheetFunction.WeekNum(Header, vbMonday) & "/" & Year(Header)
Next