Vlookup with indirect function to vba

nhinx

New Member
Joined
Aug 25, 2016
Messages
40
Office Version
  1. 2010
Hi everyone,

I have a "Summary" sheet and other sheets namely "Sheet A", "Sheet B", "Sheet C", "Sheet D", "Sheet E", "Sheet F", "Sheet G", "Sheet H", "Sheet I". In those sheets from "Sheet A" to "Sheet I" has the word "Grand Total" at the bottom in column B which varies in location due to different sets of data. Beside the word Grand Total is the total amount in Column C. While in "Summary" sheet collates the Grand Total from "Sheet A" to "Sheet I". In the Summary sheet has the following data:

A2 = "Sheet A" in C2=VLOOKUP("Grand Total",INDIRECT("'"&A2&"'!b:c"),2,0)
A4 = "Sheet B" in C4=VLOOKUP("Grand Total",INDIRECT("'"&A4&"'!b:c"),2,0)
A6 = "Sheet C" in C6=VLOOKUP("Grand Total",INDIRECT("'"&A6&"'!b:c"),2,0)
A8 = "Sheet D" in C8=VLOOKUP("Grand Total",INDIRECT("'"&A8&"'!b:c"),2,0)
A10 = "Sheet E" in C10=VLOOKUP("Grand Total",INDIRECT("'"&A10&"'!b:c"),2,0)
A12 = "Sheet F" in C12=VLOOKUP("Grand Total",INDIRECT("'"&A12&"'!b:c"),2,0)
A14 = "Sheet G" in C14=VLOOKUP("Grand Total",INDIRECT("'"&A14&"'!b:c"),2,0)
A16 = "Sheet H" in C16=VLOOKUP("Grand Total",INDIRECT("'"&A16&"'!b:c"),2,0)
A18 = "Sheet I" in C18=VLOOKUP("Grand Total",INDIRECT("'"&A18&"'!b:c"),2,0)

the formula in column C works fine as worksheet function which gathers the Grand Total for every sheets. Can you help me do a VBA code for this so that I will no longer copy those formula in the next row if there will be additional sheets like "Sheet J" to "Sheet O"

Thanks in advance,
Nhinx
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
So you basically want to use VBA instead of just using a formula that you can basically just drag down? Seems kind of like a waste of VBA. In general, it's best to only use VBA for things you couldn't otherwise do in a formula.

Here's a way to make A2...A18 a formula that you can drag down:
Code:
="Sheet "&CHAR(64+FLOOR.MATH(ROW()/2))
 
Upvote 0
Hi Ells_,

Thanks for the code. There are other concerns which are related for the Vlookup formula above this is just my sample. I just don't know how to make the Indirect works in VBA since it was not classified as worksheet function in VBA.

Many thanks,

Nhinx
 
Upvote 0

Forum statistics

Threads
1,215,372
Messages
6,124,532
Members
449,169
Latest member
mm424

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