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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,908
Messages
6,175,304
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