質問

In my file the number of sheets is flexible. They come and go (file is the same for different cost centers which uses different accounts so new tabs are added or deleted). So after creating a number of sheets (their names represent account # e.g. 401010) each of the tab is populated during the month and I can see how much of the budgeted amount is utilised.

I would like to see a list of accounts (in one sheet called "Budget") and next to each amount spent to date (must be pulled from the other sheets).

a) The problem is that when I use "SUMIFS" or VLOOKUP function, they are only applicable to existing tabs and once the tab is deleted the formula is broken (#REF!). I tried to compose a sheet name by imitating through ="'"&A8&"'!" (where cell A8 contains sheet name) but the function field shows as "Invalid".

b) I also tried to use function:

Function GetValue(sheetName As String) As Variant
GetSheetValue = ThisWorkbook.Sheets(sheetName).Range("I37") ' Cell "I37" is total spent to date
End Function

But the value is not pulled and zero is shown as a formula result.

The question is:

a) Is it possible to use cell value to make reference to a sheet in the formula? If yes, how?

b) How above macro can be modified to pull the data?

Thanks in advance!

役に立ちましたか?

解決

For a.

yes, use INDIRECT function. You can google the syntax.

For b.

add this:

Getvalue = GetSheetValue

or directly return it to your function like this.

Getvalue = Thisworkbook.Sheets(sheetname).Range("I37")
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top