View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
BEEJAY BEEJAY is offline
external usenet poster
 
Posts: 247
Default If Statement to fill in column to last row

Rick:
Thanks so much. Tried it out on my test sheet - works as expected/wanted.

IF I could trouble you again, could you explain the what and how of the X =2?


"Rick Rothstein" wrote:

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............