In VBA, you add a single quote ( ' ) to the start of your string. So:
YouString="'"+YourString
Cells(2,2)=YourString
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi, I have been reading some post and documentation, but still don't find the way my VBA program gives me the cell value like string and not like integrer.
For example if cell value contents "2,10", it takes it like the numeric value "2,1":
I've tryed:
Context: It is a formulary with some items like "2,1", ...,"2,3,1,1", "2,7", "2,8", "2,9", "2,10", ...,"3,1", "3,1,1", "3,1,1,1", "3,1,1,2", etc.
and I have to find the correct item to multiply the appropriate cuantity for the correct value or cost, but it hace some problems when trying to find items "2,10", "2,20".
Thank you in advance
Edit:
Hi @Dillon Silzer of course, here it is the piece of code that I used
Dim item As String
Dim arr() As Variant
Dim wb As Workbook
ReDim Preserve arr(1 To 1)
Folder = "C:\Users\jovan.guerra\Desktop\Jovan"
strfile = Dir(Folder & "\*.xlsx")
Do While Len(strfile) > 0
Dim aritem() As Variant
Dim arquant() As Variant
ReDim Preserve aritem(1 To 1)
ReDim Preserve arquant(1 To 1)
Path = Folder & "\\" & strfile
Set wb = Workbooks.Open(Path)
ActiveWorkbook.Worksheets("DB").Select
column = 2
counter = 0
For i = 21 To 120 'Range of cells where the Worksheet usually has the information'
Cells(i, column).Select
If ActiveCell.MergeCells = True Then 'Special condition of the requested data of my Worksheet'
item = ActiveCell.Text
quantitie = Range("U" & Trim(Str(i))).Value
Val = Range("Y" & Trim(Str(i))).Value
If Not IsError(Val) Then
If Val <> 0 Then
If IsNumeric(item) Then 'It is not supposed to happen but I have it here cause of the trouble that I mentioned'
If item <> 0 Then
item = Trim(Str(item))
stri = Split(item, ".")(0) & "," & Split(item, ".", 2)(1) 'Because when it transform the number to string, it change it to point format (Eg: 3,2 change to 3.2)'
arr(UBound(arr)) = stri
ReDim Preserve arr(1 To UBound(arr) + 1)
aritem(UBound(aritem)) = stri
ReDim Preserve aritem(1 To UBound(aritem) + 1)
arquant(UBound(arquant)) = quantitie
ReDim Preserve arquant(1 To UBound(arquant) + 1)
End If
Else
stri = item
arr(UBound(arr)) = stri
ReDim Preserve arr(1 To UBound(arr) + 1)
aritem(UBound(aritem)) = stri
ReDim Preserve aritem(1 To UBound(aritem) + 1)
arquant(UBound(arquant)) = quantitie
ReDim Preserve arquant(1 To UBound(arquant) + 1)
End If
End If
End If
End If
counter = counter + 1
Next i
[Some operations]
Erase aritem
Erase arquant
strfile = Dir
Loop
In VBA, you add a single quote ( ' ) to the start of your string. So:
YouString="'"+YourString
Cells(2,2)=YourString
Re: "still don't find the way my VBA program gives me the cell value like string and not like integer."
Format the cell as a number with two decimal places: 0.00
Then...
item = ActiveCell.Text
Item returns "2.10"
'---
Nothing Left to Lose