Compiling error when trying to access directory - vba

The following string of code keeps returning the error expected name parameter and i can not figure out where the trouble is:
With ActiveSheet.Shapes.AddPicture(Filename:="C:\Users\" & user & _
"\Dropbox (Junior-Consult)\JC - Eksterne projekter\1 JC - Virksomheder\2017-18\Dansk Supermarked - Mapping af kvalitative kommentarer\4. Analyser\" & _
country(j) & "\Billeder\" & pic_pre(i) & ws_name(j) & ".jpg",
This code however works just fine:
"C:\Users\" & user & _
"\Dropbox (Junior-Consult)\JC - Eksterne projekter\1 JC - Virksomheder\2017-18\Dansk Supermarked - Mapping af kvalitative kommentarer\4. Analyser\" & _
country(i) & "\Sentiment\" & country(i) & "_sent_o_" & ws_name(j))
i cant figure out what part of my directory string is wrong?

Your directory string is probably alright. You didn't end the first statement the right way. Maybe because your original string was so long you didn't see it.
You can use multiple lines using _ like this:
With ActiveSheet.Shapes.AddPicture(Filename:="C:\Users\" & user & _
"\Dropbox (Junior-Consult)\JC - Eksterne projekter\1 JC - Virksomheder" & _
"\2017-18\Dansk Supermarked - Mapping af kvalitative kommentarer" & _
"\4. Analyser\" & _
country(j) & "\Billeder\" & pic_pre(i) & ws_name(j) & ".jpg")
Are we answering in the comments now? I missed that in the tutorial.

Related

Trouble creating a comma-separated output string using variables

I am trying to create a string output where each of the variables are quoted and separated by a comma. This is the code I'm trying to use.
objOutputFile7.WriteLine(""& strCodeSetName & "'","'" & strCreateID & "'","'" & strSiteCode & "'","'" & strSiteName & "'","'" & strSiteName &"'",""false",,,,"false"")
I've been bouncing between 2 different errors. One that tells me a cannot use parentheses while calling a Sub. The other stating it's expecting a close-parentheses inside one of the variable names.
I've looked through online resources and could not find a close example. Could someone help me resolve my conundrum?
It's difficult to know exactly what output you expect/want, but maybe something like this?
objOutputFile7.WriteLine "'" & strCodeSetName & "','" & _
strCreateID & "','" & strSiteCode & "','" & _
strSiteName & "','" & strSiteName & "',false,,,,false"
One possibility is using the Join function. You have to create an array with all your variables...
Dim outLine as String
Dim myValues as Variant
myValues = Array(strCodeSetName, strCreateID, strSiteCode, _
strSiteName, strSiteName, "false,,,,false")
outLine = Join(myValues, ",")
objOutputFile7.WriteLine outLine

Can VBA attempt to assign to a cell a formula that is too long?

I am on Windows, if that matters. This code seems to attempt to assign a formula that is too long:
ActiveSheet.ListObjects("SegmentValues_1").ListColumns("Change").DataBodyRange.Formula = "=IFERROR(IF(INDEX(SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[CODE_ZONE],MATCH([#Modules],SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[Modules],0))=0,""Last total was ZERO"",([#CODE_ZONE]-INDEX(SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[CODE_ZONE],MATCH([#Modules],SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[Modules],0)))/INDEX(SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[CODE_ZONE],MATCH([#Modules],SegmentValues_" & (ActiveWorkbook.Sheets.count - 2) & "[Modules],0)))),""Did not exist previously"")"
Is such a thing possible? If so, how to solve it?
The long formulas work in Excel VBA quite well. Take a look at this 24 nested IF():
Sub TestMe()
Range("A1").Formula = "=IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1," & _
"IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1," & _
"IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1," & _
"IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1," & _
"IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1,IF(1=1," & _
"IF(1=1,2))))))))))))))))))))))))))))))))))))))))))))))"
End Sub
It is translated really well into Excel. Thus, take a good look at your formula, the problem should be there.

IIF ISNOTHING Expression

I'm launching a sub-report to a separate window in reporting services by a JavaScript function as seen below,
=iif(Fields!PERIOD.Value <= Cint(right(Parameters!YEARPERIOD.Value, 2)),
"javascript:void(window.open('"
& Globals!ReportServerURL
& "?"
& Left(Globals!ReportFolder, InStr(Globals!ReportFolder, "/Standard Reports"))
& "Sub Reports/Trend Breakdown"
& "&ServerName="
& REPLACE(Parameters!ServerName.value,"\","\\")
& "&CATALOG="
& Parameters!CATALOG.Value
& "&NOMINAL="
& Fields!NOMINAL.Value
& "&COMPANYCODE="
& JOIN(Parameters!COMPANYCODE.Value, ",")
& "&YEARCODE="
& LEFT(Parameters!YEARPERIOD.Value, 7)
& "&LOCATION="
& Fields!LOCATION.Value
& "&KEYLISTGROUPING="
& Fields!KEYLISTGROUPING.Value
& "&ANALYSISCODE="
& Fields!ANALYSISCODE.Value
& "&BUDGET="
& Fields!BUDGET.Value
& "&PERIOD="
& Fields!PERIOD.Value
& "&ParentReport=3
&ADD_PERIODS="
& JOIN(Parameters!ADD_PERIODS.Value, ",")
& "','_blank','width=950,height=460,top=300'))", "")
Now i'm trying to change the & Globals!ReportServerURL to the following
& IIF(IsNothing(Parameters!GetExternal.Value), "Globals!ReportServerUrl", Parameters!GetExternal.Value)
Essentially replace the ReportServerURL in the sub-report link if there is a value in the GetExternal parameter.
But it isn't updating the report server url in the sub-report correctly, but instead appending the value from the parameter to the following part of the sub-report link, see the red box,
Question i have is how can i make it append the parameter value to the following part of the link? See the red highlighted section,

SUMIF formula workbook name is unknown

I have to read to use SUMIF to check and compare the supplier number from different workbooks and if it is same then copy the Prices(using SUMIF). Everytime time the workbook can be different from which I take the prices but the sheet names and their layout will be same.So how can I write the formula in SUMIF? Can anyone help me please?
I'm stuck with this code since 2 days but couldn't figure out whats wrong.
Windows(wb_name).Activate
Range("AW18", Range("AW18").Offset(0, -44).End(xlDown).Offset(0, 44)).Formula = _
"=SUMIF('[" & dest_name & "]" & "!" & "Cu Part PVO L",$M$10:$M$2000,C19, _
"[" & dest_name & "]" & "Cu Part PVO L" & "'" & "!",$AD$10:$AD$2000)"
It looks like you have the exclamation mark in the wrong place, as well as also having too many commas.
Range("AW18", Range("AW18").Offset(0, -44).End(xlDown).Offset(0, 44)).Formula = _
"=SUMIF('[" & dest_name & "]Cu Part PVO L'!$M$10:$M$2000,C19," & _
"'[" & dest_name & "]Cu Part PVO L'!$AD$10:$AD$2000)"

VBA SumProduct Runtime Error 13

As a part of a much longer code, I am trying to include a SumProduct
Dim SumPr as Variant
SumPr=Application.WorksheetFunction.SumProduct(((Workbooks(Source2).Sheets("Prices_EUR_Adj").Range("A:A")) = Range("A" & i)) * ((Workbooks(Source2).Sheets("Prices_EUR_Adj").Range("D:D")) = "PH") * (Workbooks(Source2).Sheets("Prices_EUR_Adj").Range(ColLtr & ":" & ColLtr)))
MsgBox SumPr
However, I keep getting Runtime Error 13 for some reason. Any idea what is wrong? Source2 is properly defined, and ColLtr is letter conversion of column number I got from match; it also works ok as checked by message box.
Try using the Evaluate function instead:
Dim SumPr As Variant
SumPr = Application.Evaluate("SUMPRODUCT(--(" & Workbooks(Source2).Sheets("Prices_EUR_Adj").Range("A:A").Address & "=" & Range("A" & i).Address & ")," & _
"--(" & Workbooks(Source2).Sheets("Prices_EUR_Adj").Range("D:D").Address & "=""PH"")," & _
Workbooks(Source2).Sheets("Prices_EUR_Adj").Range(ColLtr & ":" & ColLtr).Address & ")")
MsgBox SumPr
I'm sure the WorksheetFunction.SumProduct will also work, but I was able to get the Evaluate function working easier.