GetCellValue - Sum instead

jamescooper

Well-known Member
Joined
Sep 8, 2014
Messages
840
Hello,

How would I alter the following code so that I could get the sum of F12:H12, rather than just the exact cell H12?

Code:
destcell1.Offset(r, 0).Value = GetCellValue(folderPath & fileName, "Forecast", "H12")

Many thanks.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
GetCellValue is not a built-in VBA function, so we don't know what's in it. If you have access to the source for that function, you can change it there. If you don't have access to that function, you'd have to do something like:

Code:
    destcell1.Offset(r, 0).Value = GetCellValue(folderPath & Filename, "Forecast", "F12") + _
                                   GetCellValue(folderPath & Filename, "Forecast", "G12") + _
                                   GetCellValue(folderPath & Filename, "Forecast", "H12")
 
Upvote 0
GetCellValue is not a built-in VBA function, so we don't know what's in it. If you have access to the source for that function, you can change it there. If you don't have access to that function, you'd have to do something like:

Code:
    destcell1.Offset(r, 0).Value = GetCellValue(folderPath & Filename, "Forecast", "F12") + _
                                   GetCellValue(folderPath & Filename, "Forecast", "G12") + _
                                   GetCellValue(folderPath & Filename, "Forecast", "H12")


Thanks Eric, sadly that doesn't quite work.

Any other ideas?

Thanks.
 
Upvote 0
Thanks Eric, sadly that doesn't quite work.

Why doesn't it work? Wrong result? Error? If so, what? Are you looking for an arbitrary sum instead of the specific F12:H12? Is the other workbook you're trying to access open or closed?

My original statement stands: without access to the GetCellValue function, we're shooting in the dark. If you want to sum an arbitrary range, you could put the function in a loop, and create the individual cell addresses on each pass. The last option would be to assume that the function merely gets the value of a cell in another workbook, and then write your own function to do the same, allowing for the sum of a range instead of a single cell.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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