VBA code with multiple Textboxes, but need to work with Combobox also

quarna

New Member
Joined
Oct 25, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Rather than post what works, why not post what you tried? Can only guess that you aren't using the correct identifier for your combo(s).
Please enclose code in vba code tags (see vba icon on posting toolbar).
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top