Beruflich Dokumente
Kultur Dokumente
login
tour
help
Dismiss
AnnouncingStackOverflowDocumentation
WestartedwithQ&A.Technicaldocumentationisnext,andweneedyourhelp.
Whetheryou'reabeginneroranexperienceddeveloper,youcancontribute.
Signupandstarthelping
LearnmoreaboutDocumentation
VBAVariablesheetnameinsumifformula
Isthereawaytosolvethisandmakeitwork?
excel vba excelvba
editedMar13'15at22:22
L42
12.3k
1Answer
Iseetwoissueshere:
i)wksheetisanobjectoftype'WorkSheet'andnotastring,soyoucan'tuseitasastring.
ii)wksheetisavailableinthecode,butnotintheworksheet,sowhenyoupastethefunctioninto
thecell,youneedtoexitthestringandappendthename.
Trythis:
ActiveCell.FormulaR1C1=_
"=SUMIF('"&wksheet.name&"'!C2,""=PSEC"","&wksheet.name&"!C16)"
EndSub
Note:Ifthesheetnamehasaspaceinit,youneedtosurrounditinapostrophesintheformula
otherwiseitwillcauseanerror.
editedMar19'15at19:26
answeredMar13'15at19:06
OpiesDad
2,352
19
Hi,triedwiththatchange.Gotthesameerror.Triedtochangetheplaceofthe"and&andgetthesame
wksheet.name&"!C16)"andthendebug.printthevariableandmanuallyputthevalueintoacelltoseewhat
happens.OpiesDadMar16'15at17:53
Sorry,butdon'tknowhowdebug.printworks. sekiumo Mar18'15at10:56
TriedDebug.Printwiththefiistformulayouprovided,gotFALSEinImmediate.Triedtoputthevariable
askedMar13'15at18:42
sekiumo
5
20
42
Shouldhaveonlybeenonequoteatthebeginning.Mymistake.Trytestvar="=SUMIF("&wksheet.name&
"!C2,=""PSEC"","&wksheet.name&"!C16)"OpiesDadMar18'15at13:44