abdelfattah
Well-known Member
- Joined
- May 3, 2019
- Messages
- 1,494
- Office Version
- 2019
- 2010
- Platform
- Windows
Hi
I want when select sheet from combobox1 , then will just show data don't contain zero for lastrow and ignores the whole data contains zero and what precede it .
so the original code does like this
but what I want
as you see the last column contains zero . so any lastrow contains zero should ignore the whole data contains zero and what precede it .
and the difficult part how should change the values in TOTAL row after delete data contains zero and what precede it.
as you see the result in picture 2 in TOTAL row should sum columns DEBIT,CREDIT , as to BALANCE will subtract column DEBIT from CREDIT .
thanks in advance
I want when select sheet from combobox1 , then will just show data don't contain zero for lastrow and ignores the whole data contains zero and what precede it .
so the original code does like this
but what I want
as you see the last column contains zero . so any lastrow contains zero should ignore the whole data contains zero and what precede it .
and the difficult part how should change the values in TOTAL row after delete data contains zero and what precede it.
as you see the result in picture 2 in TOTAL row should sum columns DEBIT,CREDIT , as to BALANCE will subtract column DEBIT from CREDIT .
VBA Code:
Private Sub LBoxPop()
Dim r As Long, c As Long
Dim Data() As Variant
Dim rng As Range
Set rng = ws.Cells(1, 1).CurrentRegion
ReDim Data(1 To rng.Rows.Count, 1 To rng.Columns.Count + 1)
For r = 1 To UBound(Data, xlRows)
For c = 1 To UBound(Data, xlColumns)
Data(r, c) = rng.Cells(r, c).Text
Next c
On Error Resume Next
Data(r, 6) = rng.Cells(r, 5).Interior.Color
Next r
With UserForm1.ListBox1
.ColumnCount = 5
.columnWidths = "90;290;120;120;100"
.List = Data
End With
For i = UBound(Data, xlRows) To 1 Step -1
If Data(i, 6) = 255 Then
UserForm1.ListBox1.Selected(i - 1) = True
UserForm1.ListBox1.TopIndex = i - 1
'UserForm1.ListBox1.Left = i - 1
Exit For
End If
Next
End Sub