Insert value if Cell is not empty

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
Please could someone advise me how to do the following in VBA.

I need to check for an empty cell in column B from cell "B3" down until there are no more non-empty cells in the column.

If there is a value in a cell in the B column then i need to insert in column E on that self same row, yesterdays date in format "d-mmm-yyyy".
Also i need to insert "COMPLETE" in column N also on that self same row.

Please could someone advise me how to do this in VBA.

My workbook is called "BookCheck" and the worksheet is called "Inventory"

TIA
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hi, DaveUk,
what about
Code:
Sub test()
Dim LR As Long
Const FR As Integer = 3
LR = Range("B" & Rows.Count).End(xlUp).Row
    With Range("E" & FR & ":E" & LR)
    .FormulaR1C1 = "=IF(RC[-3],TODAY()-1,"""")"
    .Value = .Value
    End With
    With Range("N" & FR & ":N" & LR)
    .FormulaR1C1 = "=IF(RC[-12],""COMPLETE"","""")"
    .Value = .Value
    End With

End Sub
if you agree to overwrite existing values in columns E and N

kind regards,
Erik
 
Upvote 0
Thanks for replying... I get "#value" in the cells.

Is it possible to use offset insted of [RC] as i find it easier to follow with offset!!

Totally confused me with all the """""""'s too!!

Thanks again
 
Upvote 0
Eric,

I took the liberty to update your code:

Sub test()
Dim LR As Long
Const FR As Integer = 3
LR = Range("B" & Rows.Count).End(xlUp).Row
With Range("E" & FR & ":E" & LR)
.FormulaR1C1 = "=IF(RC[-3]<>"""",TODAY()-1,"""")"
.NumberFormat = "d-mmm-yyyy"
.Value = .Value
End With
With Range("N" & FR & ":N" & LR)
.FormulaR1C1 = "=IF(RC[-12]<>"""",""COMPLETE"","""")"
.Value = .Value
End With

End Sub
 
Upvote 0
DaveUK

The double quotes are necessary when assigning formulae via VBA.
Using Offset would require the code to "Select" each cell, much slower than Eric's direct value assignment method.

Edit: spelling error...
 
Upvote 0
fine you sorted it out

take care of your expressions
some guys take them literally (like me this time :) )
If there is a value in a cell in the B
since you were talking about VALUES I used
=IF(B1,"yes","no") instead of =IF(B1<>"","yes","no")
hence the error

I'll never code this way again :wink:
promise :unsure:
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,569
Members
449,038
Latest member
Guest1337

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top