I want to add a product number to a collection like this:
colData.Add marke.Value + " " + pn.Value (Range-Objekte)
Every time I start the macro it runs in Runtime Error 13.
If the product number is like 256-78979-0980 everything runs fine.
If the product number is like 8898686 the error occurs.
Writing CStr(pn.Value) doesn't solve the issue.
The only solution I found is to change the format of all PNs to type text.
Then I need to go in the cell and press "Enter" after that a sign appears on the cell stating that the number is recognized as text.
After that the macro works fine for this cell but not for the others.
How can I change my data to make it work with my macro?
Avoid using + for concatenation.
Try repalcing of
colData.Add marke.Value + " " + pn.Value
with
colData.Add marke.Value & " " & pn.Value
Related
I am trying to take a value from excel and include it in the below line using VBA/Selenium:
EdgeDr.FindElementByXPath("//table[#class='mls']//td[not(#class='nowrap')and(text()='" + ThisWorkbook.Sheets("DATA").Range("C2").Value + "']").Click
The action should identify the line in a table based on a line mentioned in my Excel spreadsheet
Previous I was identifying the line itself but I needed to make it more flexible:
Previous code:
EdgeDr.FindElementByXPath("//table[#class='mls']//td[not(#class='nowrap')and(text()=2)]").Click
The part not working is:
(text()='" + ThisWorkbook.Sheets("DATA").Range("C2").Value + "']")
Anyone would be able to support ?
Thanks
If this was the original code:
EdgeDr.FindElementByXPath("//table[#class='mls']//td[not(#class='nowrap')and(text()=2)]").Click
Then this should work:
EdgeDr.FindElementByXPath("//table[#class='mls']//td[not(#class='nowrap')and(text()=" & ThisWorkbook.Sheets("DATA").Range("C2").Value & ")]").Click
Note that you introduced extra single quotes ' and I didn't because there were no before.
I am trying to read from the clipboard and place in an array. I want to validate the first line as the text: "Client Code "
I fill the array with:
tbClipBoardContents.Text = My.Computer.Clipboard.GetText()
For Each strLine As String In tbClipBoardContents.Lines
arrClipBoard.Add(strLine.ToString)
Next
When I give a variable the value of the first array entry it appears correct = "Client Code " in Visual Studio debugging.
Dim test As String = Trim(arrClipBoard(0).ToString)
However when I check using the "IF" statement it tells me it is not correct??
If test = "Client Code " Then
MsgBox("Correct Clipboard Structure")
Else
MsgBox("Not a Valid Clipboard Structure: " & Trim(arrClipBoard(0).ToString)) ' ** Fires this response.
End If
What is doing my head in is that if I copy the value of test from VS debugger and paste it in the if statement it looks like "Client Code " but this time the if statement fires the correct response.
I have tried it by filling the textbox (tbClipBoardContents) using:
tbClipBoardContents.text.split(New [Char]() {CChar(vbCrLf)})
and
tbClipBoardContents.text.split(newvbline)
with the same results.
So does this mean the true value from the clipboard for the line "Client Code " also carries some hidden characters? Any help is appreciated.
Brad
P.S. I have found that if I test the value of Mid(test,1,11) then I will get the desired result, so this is a workaround but would be interested to know what the 12th character is? Perhaps it is the "CChar(vbCrLf)"
As per my observation Trim will have removed the spaces. and you should change the condition to "ClientCode".
The final solution that worked for me was to find the trailing space using Andrew Morton's method above then
arrClipBoard.Add(Trim(Regex.Replace(strLine.ToString, Convert.ToChar(160), "")))
which effectively converted the char(160) to "".
This seems crazy basic to ask, but I can't figure out what I've done wrong. Working in Access VBA to loop through an array, but the FOR loop doesn't stop and I get a "Subscript out of range" error.
compStr = "[" & uniqueIDs(0) & "]=" & rs(uniqueIDs(0))
bnd = UBound(uniqueIDs)
For i = 1 To bnd
compStr = compStr & " and [" & uniqueIDs(i) & "]=" & rs(uniqueIDs(i))
Next i
In this example I'm using the loop to build compStr and bnd stores the array size. uniqueIDs holds 2 records (0-1) and I've confirmed that bnd and UBound(uniqueIDs) value=1. However the FOR statement continues until i=2 and of course I get an error when it executes uniqueIDs(2) on the 4th line. What am I missing? (I've pasted debug window images below)
I did a test but that successfully ran, see below implementation:
Regarding above comments on the data types: I understand why people use Variants in Access: this is because often table values are assigned to variables, and only Variant can pick up NULL. However, in your case something forced the string values to be Strings and not Variants - if I used the line commented out, it would yield Variant/Variant(0 to 1), so I used a typed dummy array - I don't know how otherwise get Variant/String(0 to 1).
Nevertheless, there was no error. Did you compile your code with Debug -> Compile? If not, could you do it and re-try? Sometimes this is necessary, otherwise some code segments newly added/removed are just not executing and the previous compiled version of the code (which is stored by Access) is making a total mess.
If it's still not working, I think you should add the rest of the code as others asked in comments to see how the variables are assigned values, and the version of Access you are using.
I'm working on a macro which supposed to compile different columns of data into an email subject, the format of the data in terms of columns and samples are provided below:
However, the cells in column AD and AI which displays data and time must contain an apostrophe in the beginning, otherwise the cell would only display time, like shown below:
What's worse, without apostrophe, vba will prompt me the error message of
type mismatch
To solve this I changed the concatenation character from + to & at this line:
.Subject = (Sheets("Summary").Cells(i, "AD").Value) & (Sheets("Summary").Cells(i, "AE").Value) & (Sheets("Summary").Cells(i, "AF").Value) & (Sheets("Summary").Cells(i, "AG").Value) & (Sheets("Summary").Cells(i, "AH").Value) & (Sheets("Summary").Cells(i, "AI").Value)
I have indeed solved the error message, but now the subject displays the date and time as value such as 42150.91666666. So now the problem I encountered is how to display the date and time properly, without adding the leading apostrophe characters.
Okay, so what i"m doing is creating a word file with my application with my labels and textboxes to create a receipt. In my word file, I am trying to write what is in a first name label beside what is in a last name label.
Here is the code I have, but I just seem to be missing something, because the word file keeps putting a huge gap between the first name and last name. I'm sure it's a very simple fix, but Google doesn't seem to be helping with what I am trying to describe.
printFile.WriteLine("Name: " & vbTab & FirstNameTextBox.Text + LastNameTextBox.Text)
I assume it must be the vbTab keyword.
which is fixed and cannot be changed.
That said you can manage a workaround as follows:
Public Const MyTab = " "
and in your code
printFile.WriteLine("Name: " & MyTab & FirstNameTextBox.Text + LastNameTextBox.Text)