Need VBA to fill the cell and back to empty

0

Dear Teacher,

Hi I am Rusli, junior student

Please help, I need some vba that can fill the cell as formula, if i choose apple then show the price in the right cell

And, if i choose else will show empty and i will type a new price directly on that cell

The file is attached

Answer
Discuss

Discussion

Please select  Chhabi Acharya's Answer as the correct answer since it seemed to work for you - this gives credit and helps future viewers see the answer more quickly.
don (rep: 1665) Feb 27, '19 at 8:32 am
Add to Discussion

Answers

1

Hi Rusli,

Please paste the following code in a module, create a button (Form Control) through the developer tab and assign the macro to the button. It will call the price in C7 if there is apple in B7 otherwise zero. Because you want to type the price in some cases, you'll have to press the button to refresh the data as per need.

Sub Price()
If Worksheets("Sheet1").Range("B7").Value <> "Apple" Then
'Or this:
'If Worksheets("Sheet1").Range("B7").Value = "" Then
Worksheets("Sheet1").Range("C7").Value = ""
End If
Worksheets("Sheet1").Range("C7").Formula = "=vlookup(B7,I7:J9,2,False)"
End Sub

Thank you!

Discuss
0

Hi Chhabi Acharya,

that's great and realy work.... Thank you very much

Warm regards,

Discuss

Answer the Question

You must create an account to use the forum. Create an Account or Login