Vba: Change list view data

Xlacs

Board Regular
Joined
Mar 31, 2021
Messages
105
Office Version
  1. 2016
Platform
  1. Windows
Hi Good People,

I' wondering if this is possible for listview, did my research but I can't seem to find the solution for this one. Hoping someone can guide me on this.. So I'm currently working a project that requires to update a listview data base on a combo box. However, Im getting an error of 'index out of bounds'

Below is my code.

VBA Code:
 Dim i As Long
Dim CN as Integer
For i = 3 to Sheets("Team H").range("A30000").end(xlUp).row
Listview1.ListItems.Add , , i - 2
CN = CN + 1

If combox1.value = "sep" then
Listview1.listitems(CN).listsubitems.add , , Sheets("Team H").cells(i , "A")
Listview1.listitems(CN).listsubitems.add , , Sheets("Team H").cells(i , "B")

End If

Next i

Dim q As Long
Dim CN2 as Integer
For q = 3 to Sheets("Team H").range("N30000").end(xlUp).row
Listview1.ListItems.Add , , q - 2
CN2 = CN2 + 1

If combox1.value = "oct" then
Listview1.listitems(CN2).listsubitems.add , , Sheets("Team H").cells(i , "N")
Listview1.listitems(CN2).listsubitems.add , , Sheets("Team H").cells(i , "O")

End If
Next q

Also, i have a condition to change the forecolor of the list items whenever the condition is met but this is giving me an error as well.

VBA Code:
Dim x As Integer
Dim RNG As Variant

For x = 1 to Listview.Listitems.count
Set RNG = Listview1.ListItems(X)
For c = 4 to 4

If Val(RNG.ListSubItems(4)) < 95 then 
listview1.listItems(x).listsubitems(c).forecolor = &HFF&

End if
Next c
Next x

This is working, however, whenever I try to change the combo box. It's not functioning..

Thanks in Advance guys.. =(
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
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