Got answer to this, below is the code - 
    Dim wbCurrent As Workbook
    Dim wsCurrent As Worksheet
    Dim nLastCol, i, j, k As Integer
    Set wbCurrent = ActiveWorkbook
    Set wsCurrent = wbCurrent.ActiveSheet
    nLastCol = wsCurrent.Cells.Find("*", LookIn:=xlValues, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    j = 0
For i = nLastCol To 1 Step -1
    j = j + 1
   ' k = InStr(1, wsCurrent.Cells(1, i).Value, "Sweep TID", vbTextCompare) > 0
        If InStr(1, wsCurrent.Cells(1, i).Value, "unitid", vbTextCompare) = 0 Then
            wsCurrent.Cells(1, i).Value = "unitid_" & j
        End If
        If InStr(1, wsCurrent.Cells(1, i).Value, "UnitName", vbTextCompare) > 0 _
        Then
            wsCurrent.Cells(1, i).Value = "UnitName_" & j
        End If
    Next i
The above code identifies the last column with the data in it and uses it in loop