Problem updating cell values using Listbox ListIndex

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to update a worksheet using the ListIndex of a Listbox, like this;

Code:
Row = ListBox1.ListIndex + 2
With Sheets("Contacts List")
Range("A" & Row).Value = TextName.Value
Range("B" & Row).Value = ComboType.Value
Range("C" & Row).Value = TextRelationship.Value
Range("D" & Row).Value = TextReligion.Value
Range("E" & Row).Value = TextTelephone.Value
Range("F" & Row).Value = TextEmail.Value
Range("G" & Row).Value = TextAddress.Value
End With
Call MsgBox("Contact updated successfully", vbInformation, "Success")

The code runs fine, gives no errors and produces the message at the end, however, the values are not being populated to the relevant cells on the worksheet.

Can anyone spot where this may be going wrong?
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
You said:
"the values are not being populated to the relevant cells on the worksheet."

Are they being added to a cell but just the wrong cell?

Are they off by 1 or two cells?
 
Upvote 0
It works for me.

I assume your using Activex controls
And the Activex controls are on sheet named "Contacts List"
And you have values in all those controls.
 
Upvote 0
Interestingly, that works, but the first row is a header so using + 1 updates the header cell but only if I try to update the first item in the Listbox, any other item does not get updated. This is weird.....
 
Upvote 0
I think I may have found the issue, possibly - I'm using this to populate the Textboxes using a Listbox Click event;


Code:
TextName.Value = ListBox1.Column(0)
ComboType.Value = ListBox1.Column(1)
TextRelationship.Value = ListBox1.Column(2)
TextReligion.Value = ListBox1.Column(3)
TextTelephone.Value = ListBox1.Column(4)
TextEmail.Value = ListBox1.Column(5)
TextAddress.Value = ListBox1.Column(6)

Watching what happens when I click the commandbutton to populate the cells after updating the textboxes, it appears that the textboxes are reverting back to their original values - just got to work out how now!
 
Upvote 0
The first item in a listbox is considered as 0
Second item is considered as 1

Normally when we use:

With

it would be like:

Code:
With Sheets("Contacts List")
.Range("A" & Row).Value = TextName.Value
.Range("B" & Row).Value = ComboType.Value
.Range("C" & Row).Value = TextRelationship.Value
.Range("D" & Row).Value = TextReligion.Value
.Range("E" & Row).Value = TextTelephone.Value
.Range("F" & Row).Value = TextEmail.Value
.Range("G" & Row).Value = TextAddress.Value
End With
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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