Public Function GetLastRow(ByVal rngToCheck As Excel.Range) As Long Dim rngLast As Excel.Range rngLast = rngToCheck.Find(What:="*", SearchOrder:=Excel.XlSearchOrder.xlByRows, SearchDirection:=Excel.XlSearchDirection.xlPrevious) If rngLast Is Nothing Then GetLastRow = rngToCheck.Rows.Count Else GetLastRow = rngLast.Rows.Count End If End Function
<pre>Sub renameColumns() With xlWSPosition .Columns("E").Insert(Excel.XlDirection.xlDown) .Range("E1").Value = "Exemption" .Cells.EntireColumn.AutoFit() Dim colValue As Excel.Range Dim lngLr As Long lngLr = GetLastRow(.Cells) For Each colValue In .Range("F2:F" & lngLr) 'Change range as needed If colValue.Value > 0 Then (Error here because F1 is string not double) 'used offset instead of range,ie (E1:E) .Range(colValue.Address).Offset(0, -1).Value = "N" Else .Range(colValue.Address).Offset(0, -1).Value = "Y" End If Next End With End Sub
'returns first empty row ;) Function GetFirstEmptyRow(wsh AS Worksheet, Optional sColName As String = "A") AS Long Return wsh.Range(sColName & wsh.Rows.Count).End(xlUp).Row + 1 End Function
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)