View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default If Statement to fill in column to last row

Maybe this?

Dim X As Long
Dim lastRow As Long
lastRow = Worksheets(1).Cells(Rows.Count, "C").End(xlUp).Row
Range("F2").AutoFill Destination:=Range("F2:F" & lastRow)

For X = 2 To lastRow
If Cells(X, "C").Value = "S" Or Cells(X, "C").Value = "B" Then
Cells(X, "F").Value = Cells(X, "D").Value
Else
Cells(X, "F").Value = 0
End If
Next

--
Rick (MVP - Excel)


"BEEJAY" wrote in message
...
Frequent (large) downloads, into Excel, requires the addition of a column,
that is filled by the use of an "IF" statement.

The following If statement works fine, when tested.
How to get it to work thru all cells, to last row.

Dim lastRow As Long
lastRow = Worksheets(1).Cells(Rows.Count, "C").End(xlUp).Row
Range("F2").AutoFill Destination:=Range("F2:F" & lastRow)

If Range("C2") = "S" Or Range("C2") = "B" Then
Range("F2").Value = Range("D2").Value
Else
Range("F2") = 0
End If
End Sub

If there is a better, more efficient way, please also advise............