problem fill data in sheet based on selection combobox on userform

Alaa mg

Board Regular
Joined
May 29, 2021
Messages
139
Office Version
  1. 2019
hi

I try finding way to fill data in specific sheet . when I select the name from combobox should match with the names are existed in COL B then insert a new row and fill data but the problem it left the rows have empty from COL C: F what i want before insert row should look for the row is empty from col c : f then should fill if there is no value from column c: f then should insert the row and fill as the code works

VBA Code:
Private Sub CommandButton1_Click()
Dim ws As Worksheet, Rng As Range, Sel As Variant

Set ws = Sheets("sheet1")
Sel = Me.ComboBox1.Value
If Sel <> "" Then
  Set Rng = ws.Columns(2).Find(Sel, lookat:=xlWhole, searchdirection:=xlPrevious) 'search backawrds!
  If Not Rng Is Nothing Then
      Cells(Rng.Row + 1, "A").Resize(1, 6).Insert Shift:=xlDown, _
       CopyOrigin:=xlFormatFromLeftOrAbove

      ws.Cells(Rng.Row + 1, "A") = Now
      ws.Cells(Rng.Row + 1, "B") = Sel
      ws.Cells(Rng.Row + 1, "C") = Me.TextBox1.Value
      ws.Cells(Rng.Row + 1, "D") = Me.TextBox2.Value
      ws.Cells(Rng.Row + 1, "E") = Me.TextBox3.Value
      ws.Cells(Rng.Row + 1, "F") = Me.TextBox4.Value

  End If
End If

Unload Me
End Sub
thanks in advance
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
65,938
Office Version
  1. 365
Platform
  1. Windows
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: how I can fixing this problem with this code
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 

Forum statistics

Threads
1,148,189
Messages
5,745,243
Members
423,936
Latest member
Conservatopia

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
Top