Changing the col. header

Guinaba

Board Regular
Joined
Sep 19, 2018
Messages
217
Office Version
  1. 2016
Platform
  1. 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?

Before running the code
1/06/2020
8/06/2020
15/06/2020
After running the code23/202024/202025/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
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
@Guinaba
Try...
VBA Code:
For i = 1 To rng.Columns.Count
         Header = rng.cells(1, i).Value. '<<<<<<<<<<<<<<<<<<<<. 1 not 11
         Header = Sheets(1).Application.WorksheetFunction.WeekNum(Header, vbMonday) & "/" & Year(Header)
    Next
 
Upvote 0

Forum statistics

Threads
1,214,553
Messages
6,120,176
Members
448,948
Latest member
spamiki

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