FMontana71
New member
- Joined
- Apr 16, 2018
- Messages
- 3
- Programming Experience
- Beginner
Good morning to you all
Let me start by stating that I am not a programmer, and all I have done so far, is based on your help in the web, with your examples.
So I have a form where the user inputs a number on a textbox -TB1 let's say 12.31, and other value (integer) on TB2. On another textbox - TB3 I made the calculation TB1 x TB2 and present the result as currency (in EU #.## €) with this code:
Private Sub TB2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
T3.Text = Val(TB1.Text) * Val(TB2.Text)
Dim VS As Decimal = TB3.Text
TB3.Text = Format(VS, "Currency")
End Sub
After this, I need to send TB3.text to Excel, which I did with the code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWB As Microsoft.Office.Interop.Excel.Workbook
Dim xlWS As Microsoft.Office.Interop.Excel.Worksheet
Dim lastRow As Long
xlWB = xlApp.Workbooks.Open("C:\Users\3787\Desktop\InTrend\Intrend - listagens.xlsx")
xlWS = CType(xlWB.Worksheets(2), Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = False
lastRow = xlWS.Range("A" & xlApp.Rows.CountLarge).End(Microsoft.Office.Interop.Excel.XlDirection.xlUp).Row + 1
With xlWS
.Range("G" & lastRow).Value = Me.TextBox3.Text
End With
End Sub
Now my problem is. that I need that this value of TB3 to be presented as number on Excel...for some reason that I cannot see, the result are presented on Excel as text...on the selected cell appears that green error "number stored as text"
How can I correct this? I need that value stored as number because I need to retrieve it back to another textbox in order to send it to another Excel sheet...please help
Many thanks
FMontana
Let me start by stating that I am not a programmer, and all I have done so far, is based on your help in the web, with your examples.
So I have a form where the user inputs a number on a textbox -TB1 let's say 12.31, and other value (integer) on TB2. On another textbox - TB3 I made the calculation TB1 x TB2 and present the result as currency (in EU #.## €) with this code:
Private Sub TB2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
T3.Text = Val(TB1.Text) * Val(TB2.Text)
Dim VS As Decimal = TB3.Text
TB3.Text = Format(VS, "Currency")
End Sub
After this, I need to send TB3.text to Excel, which I did with the code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWB As Microsoft.Office.Interop.Excel.Workbook
Dim xlWS As Microsoft.Office.Interop.Excel.Worksheet
Dim lastRow As Long
xlWB = xlApp.Workbooks.Open("C:\Users\3787\Desktop\InTrend\Intrend - listagens.xlsx")
xlWS = CType(xlWB.Worksheets(2), Microsoft.Office.Interop.Excel.Worksheet)
xlApp.Visible = False
lastRow = xlWS.Range("A" & xlApp.Rows.CountLarge).End(Microsoft.Office.Interop.Excel.XlDirection.xlUp).Row + 1
With xlWS
.Range("G" & lastRow).Value = Me.TextBox3.Text
End With
End Sub
Now my problem is. that I need that this value of TB3 to be presented as number on Excel...for some reason that I cannot see, the result are presented on Excel as text...on the selected cell appears that green error "number stored as text"
How can I correct this? I need that value stored as number because I need to retrieve it back to another textbox in order to send it to another Excel sheet...please help
Many thanks
FMontana