Nested If Then
If you prefer to compute the value directly in VBA rather than use a formula
try this .... Sub TimeCode() Dim lstrow As Long, i As Long, mx As String lstrow = Cells(Rows.Count, "N").End(xlUp).Row For i = 1 To lstrow mx = "" If IsEmpty(Cells(i, "N")) = False Then Select Case Cells(i, "N").Value Case Is 5 mx = "Early" Case 0 To 5 mx = "OnTime" Case Is < 0 mx = "Late" End Select Cells(i, "O").Value = mx End If Next i End Sub Cheers Nigel "jmdaniel" wrote in message ... I am trying to return the words "Early, "Late", or "On Time" to a column of cells, depending on what the value was in the column just to the left. It worked great when I used the macro recorder to just test for one condition, and return one of two possibilities, but when I tried to nest all the possibilities, I get an error on the Active Cell.Formula line. The debug help isn't, so I thought I would ask if I have this line written correctly. Thanks! ' Inserts Early, On Time, or Late Range("N2").Select Do If IsEmpty(ActiveCell) = False Then ActiveCell.Offset(0, 1).Select ActiveCell.FormulaR1C1 = "=IF(RC[-1]5,""Early"",IF(RC[-1]=0,""On Time"",IF(RC[-1]<0,""Late"")))""" ActiveCell.Offset(1, -1).Select End If Loop Until IsEmpty(ActiveCell) = True |
All times are GMT +1. The time now is 07:29 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com