My VBA code to edit entries in Excel only works on one column/field

edocar

New Member
Joined
Apr 15, 2018
Messages
2
Hi guys,

I have a listbox linked to an excel sheet and I have created a small "update" button that allows me to modify each entry.

However, the code only runs on the first row of code and I do not understand why it does not update the following fields. It seems as if VBA stops looking at the remainder of the code once the first action has been done.

Code:
If Me.txtbox28.Value = "" Then
MsgBox "SL No Can Not be Blank!!!", vbExclamation, "SL No"
Exit Sub
End If
SLNo = Me.txtbox28.Value
Sheets("Sheet1").Select
Dim msg As String
Dim ans As String
Dim rowselect As Doublerowselect = Me.txtbox28.Value
rowselect = rowselect + 1
Rows(rowselect).Select

Cells(rowselect, 2) = Me.txtbox1.Value

'the macro seems not to go further than here and the below is not executed. If I change the above row with any of the below, the macro will run on it, but not on the following ones.

Cells(rowselect, 3) = Me.txtbox2.Text
Cells(rowselect, 4) = Me.txtbox3.Value
Cells(rowselect, 5) = Me.txtbox4.Value
Cells(rowselect, 6) = Me.txtbox5.Value
Cells(rowselect, 7) = Me.txtbox6.Value
Cells(rowselect, 8) = Me.txtbox7.Value
Cells(rowselect, 9) = Me.txtbox8.Value
Cells(rowselect, 10) = Me.txtbox9.Value
Cells(rowselect, 12) = Me.txtbox11.Value
Cells(rowselect, 13) = Me.txtbox12.Value
Cells(rowselect, 21) = Me.txtbox20.Value
Cells(rowselect, 22) = Me.txtbox21.Value
Cells(rowselect, 23) = Me.txtbox22.Value
Cells(rowselect, 24) = Me.txtbox23.Value
Cells(rowselect, 25) = Me.txtbox24.Value
Cells(rowselect, 26) = Me.txtbox25.Value
Cells(rowselect, 27) = Me.txtbox26.Value
Cells(rowselect, 28) = Me.txtbox27.Value
Cells(rowselect, 29) = Me.txtbox28.Value
rowselect = rowselect - 1
msg = "Sl No " & rowselect & "  Successfully Updated...Continue?"
Unload Me
ans = MsgBox(msg, vbYesNo, "Update")If ans = vbYes Then
UF.Show
Else
Sheets("Sheet1").Select
End If

My question is:

what is wrong with this code? Is it a setting of VBA which is wrong?

I look forward to your feedback!

Have a nice one!

Edo
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Is this on a UserForm?

What exactly happens; do you get an error message, or are the other columns within the row just left blank?

Do you see the Successfully Updated message box?

What happens if you step (F8) through the code line-by-line?
 
Upvote 0
Hi thanks for your answer.

Yes, it is on a userform. I dont get the error message but the fields do not update with the new values. When I click on the listbox entry, all data are visible in txtboxes. I edit them, then I click on 'update' and only the value in txtbox1 gets updated. It seems that excel forgets to update the others and goes right in the 'Successfully Updated' message, which I always receive.
 
Upvote 0
What happens if you step (F8) through the code line-by-line?
Debugging VBA Code
Debugging VBA Code: Adding Breakpoints


Do you have a line earlier in the code that's something like On Error Resume Next? If yes, comment that out for testing.

Is this the code for the whole procedure?

Is it possible that you renamed the first textbox as txtbox1, but the others are still named by the default; TextBox2, TextBox3, ... etc?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,905
Messages
6,175,297
Members
452,633
Latest member
DougMo

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