I need to apply "IF "formula in whole C column till has last value in the sheet using VBA .
but i am getting error 438 if i use the following code . Plz help me
Sub test11()
With Sheets("Sheet")
.Range("c1:c" & .Cells(.Rows.Count, "A").End(xlUp).Row).Formula = "=IF(B1="",TRIM(A1),TRIM(B1))"
End With
End Sub
So your sheet name is
Sheet
orSheet1
? And OP mentioned Sheet name isSheet2
. That removes one error. Secondly, you need to setD
column as.Cells(.Rows.Count,"D").End(xlUp).Row)
instead ofA
column.Here is a very ugly code to try out: It takes last used row in count into the
Long
variable. Then set the range accordingly for setting up theformula
usingAutoFill
.Your logic seems a bit strange, but this works:
You need to double the quotes within quotes in VBA.
Another variant: