Hi.
The code below is really nice for my needs, but i am not able to make it work with comboboxes at the same time.
So i need both the 9 textboxes but also some comboxes.
I have tried a few hours and i have no idea on how to accomplish this
///////// This code looks up value from textbox1 from sheet and returns values to 9 textboxes in userform1
Sub GetData()
flag = False
i = 0
id = UserForm1.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 9
UserForm1.Controls("Textbox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 9
UserForm1.Controls("Textbox" & j).Value = ""
Next j
End If
End Sub
///////////// This code adds or edits the values from 9 textboxes to sheet
Sub EditAdd()
Dim emptyRow As Long
If UserForm1.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 9
Cells(i + 1, j).Value = UserForm1.Controls("Textbox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 9
Cells(emptyRow, j).Value = UserForm1.Controls("Textbox" & j).Value
Next j
End If
End If
End Sub
Thank you
The code below is really nice for my needs, but i am not able to make it work with comboboxes at the same time.
So i need both the 9 textboxes but also some comboxes.
I have tried a few hours and i have no idea on how to accomplish this
///////// This code looks up value from textbox1 from sheet and returns values to 9 textboxes in userform1
Sub GetData()
flag = False
i = 0
id = UserForm1.TextBox1.Value
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 9
UserForm1.Controls("Textbox" & j).Value = Cells(i + 1, j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 2 To 9
UserForm1.Controls("Textbox" & j).Value = ""
Next j
End If
End Sub
///////////// This code adds or edits the values from 9 textboxes to sheet
Sub EditAdd()
Dim emptyRow As Long
If UserForm1.TextBox1.Value <> "" Then
flag = False
i = 0
id = UserForm1.TextBox1.Value
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Do While Cells(i + 1, 1).Value <> ""
If Cells(i + 1, 1).Value = id Then
flag = True
For j = 2 To 9
Cells(i + 1, j).Value = UserForm1.Controls("Textbox" & j).Value
Next j
End If
i = i + 1
Loop
If flag = False Then
For j = 1 To 9
Cells(emptyRow, j).Value = UserForm1.Controls("Textbox" & j).Value
Next j
End If
End If
End Sub
Thank you