Apologies... my VBA skills are pretty much non-existent....
What I am trying to do is to create a macro in Excel, where data in a column (1) is replaced by the column header (SAND, LS and CS). Here is an example table:
| DEPTH | SAND | LS | CS | 
|---|---|---|---|
| 600 | 1 | -999 | -999 | 
| 700 | -999 | -999 | 1 | 
| 800 | 1 | -999 | -999 | 
| 900 | -999 | 1 | -999 | 
And here is the result when I run the macro:
| DEPTH | SAND | LS | CS | 
|---|---|---|---|
| 600 | SAND | -999 | -999 | 
| 700 | -999 | -999 | CS | 
| 800 | SAND | -999 | -999 | 
| 900 | -999 | LS | -999 | 
However, what I need is for Excel to read the Header in the first row to replace 1. Not the column letter (for example read SAND and not Columns("B:B") in the code below. I have many different files of the same format, but with different numbers of columns and different column headers, hence the question.
Here is an example of the macro I created.
Sub LithReplace()
'
' LithReplace Macro
'
'
    Range("B1").Select
    Selection.Copy
    Columns("B:B").Select
    Selection.Replace What:="1", Replacement:="SAND            ", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Range("C1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("C:C").Select
    Selection.Replace What:="1", Replacement:="LS              ", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
    Range("D1").Select
    Application.CutCopyMode = False
    Selection.Copy
    Columns("D:D").Select
    Selection.Replace What:="1", Replacement:="CS               ", LookAt:= _
        xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False, FormulaVersion:=xlReplaceFormula2
End Sub
Thanks in advance.
 
     
    
 
    