View Single Post
  #5   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

Thanks for the reminder.
Sometimes we try so hard, then miss something so basic.

"Joel" wrote:

the column you use to find the last row must be a column that contains data
in the last row. You picked column C in this case. Most worksheets have a
least one column that is always contains data. problems occur if you have
columns where there isn't data in every row.

"BEEJAY" wrote:

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