Macro to enter formula

Anna Deux

New Member
Joined
Jul 22, 2004
Messages
22
I have a workbook with two worksheets 1 and 2 (with lot or rows and columns). Let's give an example:

Sheet 1

Column A Col B

10
20
30
30
10
30

Sheet 2:

Col A Col. E
10 1000
20 2000
30 3000


I want to write a macro so I can plug in the corresponding data from Column E of sheets 2 into all the cells in column B of sheet 1 (Ex: If cell A1 of sheet 1 is 10, 1000 will be inserted into cell A2 of sheet 1. Iif cell B1 is 20, then 2000 will be inserted into cell B2 of sheet 1, etc.

Thanks for your help.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
It sounds like you don't need a macro, but just a lookup function. I put this together:
Book1
ABCD
1101000
2202000
3303000
4303000
5101000
6303000
Sheet1


And here is the lookup table on sheet2:
Book1
ABCDE
1101000
2202000
3303000
Sheet2


The formula in B1 on Sheet1 is:
=VLOOKUP(A1,Sheet2!$A$1:$E$3,5) (just copy it down the column)

Where A1 is the number to lookup, Sheet2!$A$1:$E$3 is your actual lookup table, and the 5 is the column number where you want the result pulled from (E in this case). If you have any other questions, just post back; I or someone else will be more than happy to provide clarification.

HTH,
 
Upvote 0
Thanks a lot, Tazguy37. It worked very well. I didn't expect a response that quick as I just joined today. I want to learn Excel programming with VBA. Do you know any book to recommend me?

Again, thank you.
 
Upvote 0
You're very welcome. When things are slow at work, I check in here and see what questions people have.

As to your question, I've been meaning to get VBA and Macros for Microsoft Excel for quite some time now, just haven't done it. There's a forum here for those products as well -- go read some comments and see what you think.
 
Upvote 0
Hi,

I can back up Tazguy's comments. I bought VBA and Macros from this site about a month ago and am very impressed.

Denis
 
Upvote 0

Forum statistics

Threads
1,215,140
Messages
6,123,270
Members
449,093
Latest member
Vincent Khandagale

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