Amend Cells from Userform

mucah!t

Well-known Member
Joined
Jun 27, 2009
Messages
593
Hello all,

I use the following code to delete an item selected on a listbox.
The listbox is on an userform together with some textboxes.
The values of the selected item on the listbox are retrieved from a database and shown in the textboxes.

Now i'd like to make an "adjust" button to amend the data from these textboxes. For this I need the code to select the cells, linked to the selected item in the listbox.

Ideas?


Code:
Private Sub cmbDelete_Click()
Application.ScreenUpdating = False
'REMOVE SELECTION
    Dim I As Long
    With Me.ListBox1
        For I = .ListCount - 1 To 0 Step -1
            If .Selected(I) Then Sheets("DATA").Rows(I + 1).EntireRow.Delete
        Next I
    End With
   UserForm_Initialize
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
Now i'd like to make an "adjust" button to amend the data from these textboxes. For this I need the code to select the cells, linked to the selected item in the listbox.

I am presuming from this that you want to update your database with the TextBox values.

Based on your original code, try something like the code inbetween the highlighted lines:
Code:
[COLOR=darkblue]Private[/COLOR] [COLOR=darkblue]Sub[/COLOR] cmdAdjust_Click()
   [COLOR=darkblue]Dim[/COLOR] rw [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
   [COLOR=darkblue]Dim[/COLOR] I [COLOR=darkblue]As[/COLOR] [COLOR=darkblue]Long[/COLOR]
 
   Application.ScreenUpdating = [COLOR=darkblue]False[/COLOR]
 
   [COLOR=darkblue]With[/COLOR] Me.ListBox1
      [COLOR=darkblue]For[/COLOR] I = .ListCount - 1 [COLOR=darkblue]To[/COLOR] 0 [COLOR=darkblue]Step[/COLOR] -1
         [COLOR=darkblue]If[/COLOR] .Selected(I) [COLOR=darkblue]Then[/COLOR]
            [COLOR=green]'Update record[/COLOR]
           [COLOR=red]'===============[/COLOR]
            rw = Sheets("DATA").Rows(I + 1).Row
            [COLOR=darkblue]With[/COLOR] Sheets("DATA")
               .Range("A" & rw).Value = TextBox1.Value
               .Range("B" & rw).Value = TextBox2.Value
               [COLOR=green]'[/COLOR]
               '
            [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
            [COLOR=darkblue]Exit[/COLOR] [COLOR=darkblue]For[/COLOR]
            [COLOR=green]'[/COLOR][COLOR=red]===============[/COLOR]
         [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]If[/COLOR]
      [COLOR=darkblue]Next[/COLOR] I
   [COLOR=darkblue]End[/COLOR] [COLOR=darkblue]With[/COLOR]
 
   UserForm_Initialize
   Application.ScreenUpdating = [COLOR=darkblue]True[/COLOR]
[COLOR=darkblue]End[/COLOR] [COLOR=darkblue]Sub[/COLOR]
 
Upvote 0

Forum statistics

Threads
1,224,557
Messages
6,179,508
Members
452,918
Latest member
Davion615

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