Alex Piotto
Board Regular
- Joined
- Jul 5, 2016
- Messages
- 82
- Office Version
- 2007
- Platform
- Windows
Hi! Here we go again...
Ii have 3 column of data. A, B, C. From row 2 to 200.
I have also a listbox, where i can show the values from the 3 columns at easy.
But column C sometimes may not have a value. It will be blank.
And in the listbox I can see all the rows from 2 to 200 (actually until the last row with value) even if there is a blank in C.
What I would like to achieve is show in the listbox only the rows that have a value in column C.
Here is the code that shows everything. Is not entirely mine. Part scavenging, part modifying...
Ii have 3 column of data. A, B, C. From row 2 to 200.
I have also a listbox, where i can show the values from the 3 columns at easy.
But column C sometimes may not have a value. It will be blank.
And in the listbox I can see all the rows from 2 to 200 (actually until the last row with value) even if there is a blank in C.
What I would like to achieve is show in the listbox only the rows that have a value in column C.
Here is the code that shows everything. Is not entirely mine. Part scavenging, part modifying...
VBA Code:
Sub VERIFICA()
'Worksheets("INSERZIONE").ListBox1.Visible = True
'Worksheets("INSERZIONE").CommandButton1.Visible = True
'Worksheets("INSERZIONE").CommandButton2.Visible = True
Dim rngName As Range
Dim ws As Worksheet
Dim i As Integer
Set ws = Worksheets("INSERZIONE")
Worksheets("INSERZIONE").ListBox1.Clear
Worksheets("INSERZIONE").ListBox1.ColumnCount = 3
Dim LastRow As Long
LastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row
For i = 1 To LastRow
If ws.Cells(i, 1).Value <> vbNullString Then Worksheets("INSERZIONE").ListBox1.AddItem ws.Cells(i, 1).Value
If ws.Cells(i, 2).Value <> vbNullString Then Worksheets("INSERZIONE").ListBox1.List(i - 1, 1) = ws.Cells(i, 2).Value
If ws.Cells(i, 3).Value <> vbNullString Then Worksheets("INSERZIONE").ListBox1.List(i - 1, 2) = ws.Cells(i, 3).Value
Next i
Worksheets("INSERZIONE").ListBox1.Selected(0) = True
End Sub