abenitez77
Board Regular
- Joined
- Dec 30, 2004
- Messages
- 149
I have a spreadsheet that gets created dynamically..and has x number of columns. It has column header names and sometimes these could contain duplicates. I want to rename one by putting a "2" at the end of the column header so that there are no duplicates. How can i do this with vba?
I tried code to help me get close but does not work...It errors out in the If Application... row
'Rename any Duplicate Column names
With Sheets(myCurrentSheet)
For thisCol = lastCol To 2 Step -1
If Application.Match(.Cells(1, thisCol).Value, Range(.Cells(1, 1), .Cells(1, lastCol)), 0) <> thisCol Then
' If Application.Match(.Cells(1, thisCol).Value, .Range("1:1"), 0) < thisCol Then
MsgBox ("Duplicate")
End If
Next thisCol
End With
I tried code to help me get close but does not work...It errors out in the If Application... row
'Rename any Duplicate Column names
With Sheets(myCurrentSheet)
For thisCol = lastCol To 2 Step -1
If Application.Match(.Cells(1, thisCol).Value, Range(.Cells(1, 1), .Cells(1, lastCol)), 0) <> thisCol Then
' If Application.Match(.Cells(1, thisCol).Value, .Range("1:1"), 0) < thisCol Then
MsgBox ("Duplicate")
End If
Next thisCol
End With