I hate blanks

m_in_spain

Board Regular
Joined
Sep 28, 2018
Messages
72
Office Version
  1. 365
Platform
  1. Windows
I am trying to retrieve data from a table in the workbook called Charge002.
The below code seems to work OK but I was hoping not to retrun blank rows to the ListView2

Here is the table:
Screenshot 2024-07-01 205326.png


VBA Code:
For Each rngCell In Range("Charge002")
    If rngCell.Column = Range("Charge002").Columns(1).Column Then
        If Not IsEmpty(rngCell.Value) Then
            Set itmX = UserForm1.ListView2.ListItems.Add(, , rngCell.Value)
            With itmX
                For h = 1 To Range("Charge002").Columns.Count - 1
                    .SubItems(h) = rngCell.Offset(0, h)
                Next h
            End With
        End If
    End If
Next rngCell

Any help would be appreciated. I dont mind it returning the blank rows, if I must, but can they be returned under the data filled rows?


Many thanks in advance
 

Attachments

  • Screenshot 2024-07-01 205326.png
    Screenshot 2024-07-01 205326.png
    11.2 KB · Views: 9

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hard to be sure without data to experiment with, but see if this makes a difference (not tested)
VBA Code:
    For Each rngCell In Range("Charge002")
        If rngCell.Column = Range("Charge002").Columns(1).Column Then
            If Trim(Replace(CStr(rngCell.Value), Chr(160), "")) <> "" Then
                Set itmX = UserForm1.ListView2.ListItems.Add(, , rngCell.Value)
                With itmX
                    For h = 1 To Range("Charge002").Columns.Count - 1
                        .SubItems(h) = rngCell.Offset(0, h)
                    Next h
                End With
            End If
        End If
    Next rngCell
 
Upvote 0
Solution
Hard to be sure without data to experiment with, but see if this makes a difference (not tested)
VBA Code:
    For Each rngCell In Range("Charge002")
        If rngCell.Column = Range("Charge002").Columns(1).Column Then
            If Trim(Replace(CStr(rngCell.Value), Chr(160), "")) <> "" Then
                Set itmX = UserForm1.ListView2.ListItems.Add(, , rngCell.Value)
                With itmX
                    For h = 1 To Range("Charge002").Columns.Count - 1
                        .SubItems(h) = rngCell.Offset(0, h)
                    Next h
                End With
            End If
        End If
    Next rngCell
Brilliant, Thank you, yes it worked perfectly.
 
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