Editing data from another sheet using Combobox?

jmpatrick

Active Member
Joined
Aug 17, 2016
Messages
477
Office Version
  1. 365
Platform
  1. Windows
Happy Friday!

Today I'm trying to give users the ability to edit data on a sheet using a userform.

Here's a screen shot...

edit garage.png


Here's my code:

VBA Code:
Private Sub cmdUpdateGarageHandling_Click()
Dim EditGarageHandling_id As String
EditGarageHandling = Trim(EditGarageHandling.Text)
LastRow = Worksheets("GarageHandling").Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
If Worksheets("GarageHandling").Cells(i, 1).Value = EditGarageHandling Then
   Worksheets("GarageHandling").Cells(i, 1).Value = EditGarageHandling.Text
End If
Next
        
        Call cmdResetDeleteGarageHandling_Click
        
        MsgBox ("Garage Handling Successfully Updated!")

End Sub

The user would select data from the combobox, make changes and hit update to edit the data in sheet (GarageHandling).

The current code doesn't error out, but it doesn't edit anything either.
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
You are searching for the value of EditGarageHandling & if it's found you are then putting the same value back into the cell.
 
Upvote 0
You are searching for the value of EditGarageHandling & if it's found you are then putting the same value back into the cell.

I'm not sure the best way to do this with one combobox. I just want to be able to select data, edit the data in the same combobox and hit update.

Not sure if it's possible because it's early and I'm dumb.
 
Upvote 0
I would suggest putting a textbox in there, select the value from the combo & then edit that in the textbox.
 
Upvote 0
If you need help with that, just shout.
 
Upvote 0
If you need help with that, just shout.

I got it cooking pretty easy. Userform changed...

edit garage 2.png


Update code changed...

VBA Code:
Private Sub cmdUpdateGarageHandling_Click()
Dim EditGarageHandling_id As String
EditGarageHandling = Trim(EditGarageHandling.Text)
LastRow = Worksheets("GarageHandling").Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
If Worksheets("GarageHandling").Cells(i, 1).Value = EditGarageHandling Then
   Worksheets("GarageHandling").Cells(i, 1).Value = EditGarageHandlingReturn.Text
End If
Next
        
        Call cmdResetDeleteGarageHandling_Click
        
        MsgBox ("Garage Handling Successfully Updated!")

End Sub

Added this to mirror the combobox data to the new edit textbox...

VBA Code:
Private Sub EditGarageHandling_Change()
     EditGarageHandlingReturn.Value = EditGarageHandling.Value
End Sub

The issue I'm having is with the reset: cmdResetDeleteGarageHandling_Click.

VBA Code:
Private Sub cmdResetDeleteGarageHandling_Click()
        With Me
            .EditGarageHandling.Clear
            .EditGarageHandlingReturn.Value = ""
        End With
        UserForm_Initialize
        EditGarageHandling.SetFocus
        Me.cmdDeleteModel.Enabled = False
End Sub

It clears the textbox but the combobox won't clear.

Thoughts?
 
Upvote 0
Try using
VBA Code:
        Private Sub EditGarageHandling_Click()
EditGarageHandlingReturn.Value = EditGarageHandling.Value
End Sub
 
Upvote 0
Do you have any code in the initialise event that puts a value into the combo?
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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