Reputation: 43
I'm trying to get the userform to update other fields when I update a textbox.
My problem is that even though I write TextBox1.Value
it still treats my input as text and thus only finds a match if I format my numbers in the table as text.
Below is my current code:
Private Sub TextBox1_Change()
On Error Resume Next
ComboBox2.Value = Application.WorksheetFunction.Index(Sheets("Projekt").Range("Projektnamn"), Application.WorksheetFunction.Match(TextBox1.Value, Sheets("Projekt").Range("Projektnr"), 0), 1)
End Sub
This code works but is not connected to the userform. (I put in a number (155001) that the range:"Projektnr" contains) So it is the first part of the Match function that doesn't work.
Private Sub TextBox1_Change()
On Error Resume Next
ComboBox1.Value = Application.WorksheetFunction.Index(Sheets("Projekt").Range("Projektnamn"), Application.WorksheetFunction.Match(155001, Sheets("Projekt").Range("Projektnr"), 0), 1)
End Sub
I tried gizlmeiers suggestion and it still refuses to find a match. I attatch that code as well:
Private Sub TextBox1_Change()
On Error Resume Next
Test = CInt(TextBox1.Value)
ComboBox1.Value = Application.WorksheetFunction.Index(Sheets("Projekt").Range("Projektnamn"), Application.WorksheetFunction.Match(Test, Sheets("Projekt").Range("Projektnr"), 0), 1)
Upvotes: 0
Views: 2667
Reputation: 1922
So you are trying to compare two numbers, but the one in the textbox is interpreted as a string?
You can tell vba to interpret it as a number by using CINT()
CINT(TextBox1.Value)
Upvotes: 0