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
Related
I have the goal to write a formula in a set of rows. Some references in the formula have to change each row.
I implemented the following script:
Dim i As Integer
Dim formcolM As String
Dim temprng As String
For i = 0 To 100
formcolM = "NUMBERVALUE(IF(Q" & i & "=""Bedarf kum."";A" & i & ";IF(Q" & i & "=""Ist"";OFFSET(A" & i & ";-1;0);IF(Q" & i & "=""Lz."";OFFSET(A" & i & ";-2;0);IF(Q" & i & "=""Ist+Lz.-Bedarf"";OFFSET(A" & i & ";-3;0);)))))"
Let temprng = "M" & i
Range(temprng).Select
ActiveCell.Value = "\=" & formcolM
next i
With this script I am writing a string each row in my excel table at column M.
I noticed that if the formula hasn't the symbol "\" , you can find an error .
In order to avoid the error I thought to leave the symbol "\" and to use a trick deleting it after (because I don't know how to solve with R1C1 formula. I read some answers on Stackoverflow, but unfortunately I did not understand )
The replacing script after the for cycle:
Columns("M:M").Replace What:="\=", Replacement:="=", LookAt:=xlPart
The strange thing is that the macro doesn't delete it.
Infact when the script finishes , it seems that nothing happened, without errors. But if I want substitute "\=" with another symbol, for example "*", the replacing script works.
I did not understand if the problem is :
the replace method did not recognized the symbol "=" to search
I cannot use the replace method because the symbol "=" disturbs in some way , I don't know in what.
OR, is there another simplest way to get this task done?
Someone could help me in order to fix? I should have the formula working in the column M , automatically with vba (not with another formula in the excel sheet) .
Thanks in advance for your time.
We can apply the formula directly. The issue is that vba is very US-EN Centric and all formula when using the .Formula needs to be in that format.
Also since your formula refers to values in a row 3 above the one in which it is put we need to start the loop at 4 not 0. There is no row 0
There are two ways, in US-En format with English functions and , as the deliminator using .Formula:
Dim i As Integer
For i = 4 To 100
Range("M" & i).Formula = "=NUMBERVALUE(IF(Q" & i & "=""Bedarf kum."",A" & i & ",IF(Q" & i & "=""Ist"",OFFSET(A" & i & ",-1,0),IF(Q" & i & "=""Lz."",OFFSET(A" & i & ",-2,0),IF(Q" & i & "=""Ist+Lz.-Bedarf"",OFFSET(A" & i & ",-3,0),)))))"
Next i
Or using .FormulaLocal and the formula as you would write it in your native tongue.
Dim i As Integer
For i = 4 To 100
Range("M" & i).FormulaLocal = "=NUMERO.VALORE(SE(Q" & i & "=""Bedarf kum."";A" & i & ";SE(Q" & i & "=""Ist"";SCARTO(A" & i & ";-1;0);SE(Q" & i & "=""Lz."";SCARTO(A" & i & ";-2;0);SE(Q" & i & "=""Ist+Lz.-Bedarf"";SCARTO(A" & i & ";-3;0);)))))"
Next i
By the time I got this worked out, Scott already had an answer. I just wanted to post your original code modified to work. I would suggest his method.
Sub TestScript()
Dim i As Integer
Dim formcolM As String
Dim temprng As String
For i = 4 To 100
formcolM = "NUMBERVALUE(IF(Q" & i & "=" & "Bedarf kum." & ";A" & i & ";IF(Q" & i & "=" & "Ist" & ";OFFSET(A" & i & ";-1;0);IF(Q" & i & "=" & "Lz." & ";OFFSET(A" & i & ";-2;0);IF(Q" & i & "=" & "Ist+Lz.-Bedarf" & ";OFFSET(A" & i & ";-3;0);)))))"
temprng = "M" & i
Sheets("Sheet1").Range(temprng).Select
ActiveCell.Value = " = " & formcolM
Next i
End Sub
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,
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)"
How do I write to the columns in a .log file?
I.e there are columns for "Log Text","Component","Date/Time"
How do I specify these when writing to a file?
I've got half of it working:
dim str As String ="<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & """" & " date=""" & Now.ToShortDateString & """ component=""" & component.ToString & """" & " type=""1""" & " Thread=""" & t & """" & ">"
File.AppendAllText(logfile, str & vbCrLf)
But the component, date / time and thread values arent displaying properly.
What am I missing ?
*edited
The file path is "C:\Programdata\server.log"
So some of the text is getting into it in the right place, just not all of it.
So the log text column will get populated with "message" and thread comes in with the number but the date/time and component are empty.
I'd attach a pic but i dont have enough rep :/
In a sentance, Im trying to replicate this:
http://www.jetico.com/web_help/bcwipe6_enterprise/img/log_viewer.jpg
but not all of my columns are displaying data.
Try dividing your data into columns using commas as suggested by #Blackwood, but use string.format as you seem to have lots of extra "" in there
Dim str As String = String.Format("![LOG[{0}]LOG]!,time={1}, <date= {2}, component= {3}, type=1, Thread={4}", Message, Now.ToLongTimeString, Now.ToLongDateString, component.ToString, t)
File.AppendAllText(logfile, Str() & vbCrLf)
I'm not sure what you are doing with the <> tags.
Solved.
This is to do with the format of the data I was trying to write.
Time has to be in the format
Now.ToLongTimeString & "." & Now.Millisecond & "-60"
and date has to be seperated with - instead of /
Dunno why - when viewed the time doesnt go to that length and the date is displayed with "/"
The viewer im using for the log was cmtrace.
This was the line that got it working was ..
<![LOG[" & message & "]LOG]!><time=""" & Now.ToLongTimeString & "." & Now.Millisecond & "-60" & """" & " date=""" & d & """ component=""" & component.ToString & """" & " type=""1" & """ Thread=""" & t &""">
I have the following code in my procedure built up to be evaluated within a much larger loop
CalculationHoldArray(Loopcount) = "'[" & Usefile1.Name & "]" & _
Worksheet1 & "'!" & Cells1 & ",'[" & Usefile2.Name & "]" & _
Worksheet2 & "'!" & Cells2
Sheets("ECAP PARAMETER INPUTS").Cells(31, "F").Value =
Application.WorksheetFunction.Sum(CalculationHoldArray(Loopcount))
The string returned for the array is:
'[Control Model v1.35- nonfunctional.xlsm]Input'!E2, _
'[Control Model v1.35- nonfunctional.xlsm]Input'!E3
But the application.worksheetfunction.sum is returning an error 1004. "Unable to get the sum property of the worksheet class". Anyone know what the issue is that it won't let me use the sum property here?
Instead of using the Application.Worksheet.Function command, simply use the Evaluate command, which requires adding in the "sum" and brackets to make it a valid formulae.
But I have found a solution- instead of using the application.worksheet.function command, I can simply use the "EVALUATE" command, just required adding in the "sum" and brackets to make it a full formulae –