Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

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: 1989) 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