edit header names by mapping array of header names to array of new header names

capson

Board Regular
Joined
Jul 9, 2010
Messages
107
I have googled for hours to "Change header names by mapping array of old header names to array of new header names"

The closest I have come is the code below that mappes a array of names to the first n cells

Is it possible to alter the following code or does someone have a different approach?

Thanks

Code:
<code style="margin: 0px; padding: 0px; font-style: inherit;">Sub TestHeaderRow1()  On Error GoTo ErrorHandler   Dim headerValues As Variant  Dim sht As Excel.Worksheet   headerValues = Array("Field1", "Field2", "Field3")   Set sht = ActiveSheet   Call PopulateHeaderRow(headerValues, sht) ProgramExit:  Exit SubErrorHandler:  MsgBox Err.Number & " - " & Err.Description  Resume ProgramExitEnd SubSub PopulateHeaderRow(headerValues As Variant, sht As Excel.Worksheet) Dim rngCount As LongDim rngHeader As Excel.Range   ' count number of values to determine number of header cells being used  rngCount = UBound(headerValues) + 1   ' set range reference to exact number of header cells  Set rngHeader = sht.Range(sht.Cells(1, 1), sht.Cells(1, rngCount))   ' write array values to header  rngHeader.Value = headerValues End Sub</code></pre>
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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