alternating 2 vlookups for 1 cell

wizbasky

New Member
Joined
Apr 1, 2011
Messages
2
I have a spreadsheet I am working on, and I have limited excel formula experience, i can do a Vlookup formula but thats about it.

what i was to do is this.

Imagine a 2 page spreasheet,

Page 1 / Cell (A1) = abc Cell (A2) = the vlookup foruma i guess


Page 2 = the list of codes & prices

normaly like this

Col 1 Col 2 Col 3
abc $100 $3.66
def $150 $5.88
ghi $125 $4.50
jkl $110 $3.99


Column 1 = codes
Column 2 = Each price
Column 3 = Lineal Meter price


I want to figure out a way to have a button on page 1, that you can click, that swaps between EA & LM prices.

Yes I could just put 2 columns next to each other and have both prices sitting next to each other, but it's messy, and makes the spreadsheet failry wide, I want to clean it up and make it neat looking.

Is it possible to make a button that swaps out the vloopup or some other forumula so it swaps between prices ( EA & LM)
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Wizbasky, welcome to the board'

You could use 2 buttons and add code to each button as below;
Code:
Sub EAprice()
    Range("A2").Select
    ActiveCell.Formula = "=VLOOKUP(A1,Sheet2!A1:C4,2,0)"
End Sub
 
Sub LMprice()
    Range("A2").Select
    ActiveCell.Formula = "=VLOOKUP(A1,Sheet2!A1:C4,3,0)"
End Sub

Or if you use a reference cell (I used G1 in this example) you can use a select case statement;
Code:
Sub Bothprices()
Select Case Range("G1").Value
Case Is = "EA"
    Range("A2").Select
    ActiveCell.Formula = "=VLOOKUP(A1,Sheet2!A1:C4,2,0)"
 
Case Is = "LM"
    Range("A2").Select
    ActiveCell.Formula = "=VLOOKUP(A1,Sheet2!A1:C4,3,0)"
 
    End Select
End Sub

HTH
Colin
 
Last edited:
Upvote 0
Hello RS2K,

This...
Sub EAprice()
Range("A2").Select
ActiveCell.Formula = "=VLOOKUP(A1,Sheet2!A1:C4,2,0)"
End Sub


Plus the other one, looks liek it will do something, but how do i assign this code to a button? I have really basic skills.
 
Upvote 0
If you use a command button from the controls toolbar, right click>view code and paste it in there. If it's a command button from the forms toolbar, right click>assign macro and choose a amcro to attach to the button.

If you PM (private message) me your email, I will send you a sample workbook showing this, so you can disect were things go.

HTH
Colin
 
Upvote 0

Forum statistics

Threads
1,224,618
Messages
6,179,917
Members
452,949
Latest member
beartooth91

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