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
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>