Macro Button to Change Lookup Values

dcliffo

Board Regular
Joined
Jun 18, 2003
Messages
148
I have a spreadsheet that utilizes vlookup in another spreadsheet to update specific values for each quarter during the current year. I want to incorporate a button that changes all of these values (looks up values from different columns) depending on whether I want to view "proposed" values or "approved" values. I know I can record a macro and capture updating each of these manually, but is there an easier way of finding and replacing values within a formula for a particular column of data? Thanks for the help in advance.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
I have a spreadsheet that utilizes vlookup in another spreadsheet to update specific values for each quarter during the current year. I want to incorporate a button that changes all of these values (looks up values from different columns) depending on whether I want to view "proposed" values or "approved" values. I know I can record a macro and capture updating each of these manually, but is there an easier way of finding and replacing values within a formula for a particular column of data? Thanks for the help in advance.

dcliffo,
This is a 'brute force' method to replace each VLOOKUP formula...but it works!
You didn't post a sample or your data so we didn't have a range for either the 'Proposed' data
or the 'Approved' data. The example below uses an 'Inputbox' and 'Select Case'.
If neither case is selected, you are prompted to 'try again'.
Perpa

Code:
Sub ReplaceMyVlookups()	
TryAgain:	
    myStatus= Inputbox("Input '1' for 'Proposed', '2' for 'Approved'")	
	
            Select Case myStatus	
                    Case 1 'Proposed	
	      'Enter your formulae similar to the following for each VLOOKUP
	      'where 'rangename1' is a defined range name...OR actual range, ie. K15:P25
                        Range("C5").value="=VLOOKUP(B5,K15:P25,3,FALSE)"    'Change to suit	
	        Range("C6").value="=VLOOKUP(B6,K15:P25,4,FALSE)"
	      '  Range(.....etc...etc
                    Case 2   'Approved	
	        'where 'rangename2' is a defined range name...OR actual range, ie. K27:P37
                        Range("C5").value="=VLOOKUP(B5,K27:P37,3,FALSE)"    'Change to suit	
	        Range("C6").value="=VLOOKUP(B6,K27:P37,4,FALSE)"
	       ' Range(.....etc...etc
	    Case else
	         Msgbox("You didn't select '1' or '2'...try again")
	         goto TryAgain
            End Select	
	
End Sub
 
Upvote 0
Thank you for your reply. This was posted quite a while back and since then I just came up with the following: I used a drop-down box with selection of either Proposed or Approved. I used a vlookup which if this cell matched Proposed, then it looked up a different column value then if the selection was Approved. It works...Thanks for the reply.
 
Upvote 0

Forum statistics

Threads
1,202,909
Messages
6,052,495
Members
444,587
Latest member
ezza59

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