IF NOT ISBLANK - syntax issue - excel-2016

=IF(NOT(ISBLANK(VLOOKUP(Table1[Company Name],Billing_Info[#All],5,FALSE) & ", " &VLOOKUP(Table1[Company Name],Billing_Info[#All],6,FALSE) & " " &VLOOKUP(Table1[Company Name],Billing_Info[#All],7,FALSE),""))
What am I doing wrong - get wrong number of arguments? Trying to eliminate the comma if there is no data.

Related

The SELECT statement includes a reserved word

So when I try to run my code I get a Runtime Error '3141' "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect."
Here is my code
strSQL5 = " SELECT DatePart('m',[gs_MultiList_Daily/monthly]![Test_Date]) AS Char, MonthName(DatePart('m',[Test_Date])) AS [Month], DatePart('yyyy',[Test_Date]) AS [Year], Sum([gs_MultiList_Daily/monthly].LeaksLogged) AS LeaksLogged, Sum([gs_MultiList_Daily/monthly].[ME Samples]) AS [ME Samples], Sum([gs_MultiList_Daily/monthly].MSampleLogged) AS MSampleLogged, Sum([gs_MultiList_Daily/monthly].Saddle) AS Saddle, Sum([gs_MultiList_Daily/monthly].EntranceDia) AS EntranceDia, Sum([gs_MultiList_Daily/monthly].TappingTee) AS TappingTee, [gs_MultiList_Daily/monthly].LDIW, [gs_MultiList_Daily/monthly].[X-Ray], [gs_MultiList_Daily/monthly].[ETSP Inspection], [gs_MultiList_Daily/monthly].DFT, [gs_MultiList_Daily/monthly].CDT, Sum([gs_MultiList_Daily/monthly].[Mount Photos]) AS [Mount Photos], Sum([gs_MultiList_Daily/monthly].[Melt Index]) AS [Melt Index], Sum([gs_MultiList_Daily/monthly].PSampleLogged) AS PSampleLogged, Sum([gs_MultiList_Daily/monthly].Density) AS Density, " & _
" Sum([gs_MultiList_Daily/monthly].PE_WT) AS PE_WT, Sum([gs_MultiList_Daily/monthly].OOR) AS OOR, " & _
" Sum([gs_MultiList_Daily/monthly].Poly_OD) AS Poly_OD, Sum([gs_MultiList_Daily/monthly].[WaterBath Out]) AS [WaterBath Out], Sum([gs_MultiList_Daily/monthly].[WaterBath In]) AS [WaterBath In], Sum([gs_MultiList_Daily/monthly].FTIR) AS FTIR, Sum([gs_MultiList_Daily/monthly].OIT) AS OIT, Sum([gs_MultiList_Daily/monthly].[Steel WT]) AS [Steel WT], Sum([gs_MultiList_Daily/monthly].[Steel Hardness]) AS [Steel Hardness], Sum([gs_MultiList_Daily/monthly].[Steel OD]) AS [Steel OD], Sum([gs_MultiList_Daily/monthly].[TIMP Corrosion]) AS [TIMP Corrosion], Sum([gs_MultiList_Daily/monthly].[Chem Analysis]) AS [Chem Analysis], Sum([gs_MultiList_Daily/monthly].[Steel Mounts]) AS [Steel Mounts], Sum([gs_MultiList_Daily/monthly].[Mounts Polished]) AS [Mounts Polished], Sum([gs_MultiList_Daily/monthly].Etch) AS Etch FROM [gs_MultiList_Daily/monthly] " & _
" GROUP BY DatePart('m',[gs_MultiList_Daily/monthly]![Test_Date]), MonthName(DatePart('m',[Test_Date])), DatePart('yyyy',[Test_Date]) " & _
" ORDER BY DatePart('yyyy',[Test_Date]) "
This is exactly how it is displayed on the window. The SELECT statement is really long and did not fit in a single line so I broke it up into 3 using " & _ " I also have spaces at both ends of the " so im clueless to where the error is coming from. Can someone please direct me to the correct path ? thank you!
CHAR is a reserved word, don't use it as an alias (or add [] brackets, but really, don't use it).
Generally, when you encounter this error, run each field name through the list of reserved words.

Comparing values in Two variable using VBA Like operator

I would like to compare values(string ) stored in two variable, just like we can compare a variable with a string using like operator
So basically i would like to use "like "operator and have two variable contents comparison or get simililar functionality .
Below is the snippet of the code . Please guide me
If ( nametwo Like " * " & monthname & " * " ) OR ( nametwo Like " * " & yearname& " * " ) Then
'some action
Endif
Note : nametwo , monthname and yearname are string variables
The Answer to the question was proper spacing
If (nametwo Like "*" & monthname & "*") And (nametwo Like "*" & yearname & "*") Then
csworksheetcount = ws.Index
End If

recordset.GetString in Access VBA Query returns an extra character after the result

I have a query that I execute through VBA in Access 2010. The result of the query should be AFR, but it returns AFR with an extra line below it. I have added the "'" character to make the extra line visible.
TempHold = rs.GetString
Debug.Print "'" & TempHold & "'"
Returns this:
'AFR
'
But should return this:
'AFR'
I have tried using the below code, but none of the If statements evaluate as True. The code should check for a " ", a vbNewLine, or vbCrLf character but none evaluate as true. Does anyone know of any additional characters that would result in a new line?
If Right(TempHold, 1) = " " Then
TempHold = Left(TempHold, Len(TempHold) - 1)
ElseIf Right(TempHold, 2) = vbNewLine Or Right(TempHold, 2) = vbCrLf Then
TempHold = Left(TempHold, Len(TempHold) - 2)
End If
Use:
Asc(Right(TempHold, 1))
to get the Ascii character code.
Once you've found the character code (which, as you wrote in your comment, was 13), you can use your code to remove it:
If Right(TempHold, 1) = Chr(13) Then
TempHold = Left(TempHold, Len(TempHold) - 1)
End If
In this case, you can also use vbCr, which is the same as Chr(13).
The best way to get rid of the carriage return in my opinion is to stop it being created in the first place. This method is a lot tidier than having to remove the last character.
In the .GetString method there is a parameter for RowDelimiter which by default is set to be a carriage return. However you can change this to be whatever you want including a zero length string as follows:
rs.GetString(, , , "")
If you run your debug again with this code:
rs.GetString(, , , "")
Debug.Print "'" & TempHold & "'"
You will get this result:
'AFR'
Remember if you want something different to be placed between rows then just change the zero length string to whatever you need.

What does "& _" mean in VB?

I'm copying some query statements from a legacy VB app to a C# app. I am not familiar with VB, although looking at it makes me want a VB (Victoria Bitter). I have come across queries constructed like this:
*SELECT dp_duckbill_accounts.platypus_no AS duckbill, t_accounts.name AS Name " & _
"FROM t_accounts INNER JOIN dp_duckbill_accounts ON t_accounts.account_no = dp_duckbill_accounts.account_no " & _
"ORDER BY dp_duckbill_accounts.platypus_no*
The "& _" give me pause. If it was just "&" I would think it corresponds to "+" in C# to concatenate strings. But what in the world is the point of the underscore? Note the ampersand and the underscore are separated by a space.
The underscore is the line continuation character. It allows the concatenation to include a different line. Like so:
x = "Hello " & "World"
x = "Hello " & _
"World"
'this won't compile (pre vb.net 2010, anyway)
x = "Hello " &
"World"
Line Continuation on MSDN
How to: Break and Combine Statements in Code (Visual Basic)
_ means continue the statement on the following line.
so ... & _ means continue concatenating the string on the following line.
text = "One line string"
text = "Two line " & _
"string"
That is just a line continuation character that lets you continue to the next line.
& - is used for string concatenation in same line.
example - sConcatenatedString = "First" & "Second"
& _ - is used For string concatenation in different lines.
example - sConcatenatedString = "First" &_
"Second"

VBA Runtime error 1004 on Cells(..).Formula

I can't make this simple command work:
Cells(l, 7).Formula = "=" & var1 & " * " & var2 & " * " & var3 & " / 252"
I can paste the inspected formula string value in Excel and it works as expected.
Cells(l,7) is a proper reference, as I can inspect its value.
Inspected formula on debug:
"=86710597,9409 * 0,02 * 0,35 / 252"
The problem is when a variable is represented as string it will have the system's decimal point. In your case it is a comma so you need to convert it to dot, for example using replace() function.