Excel VBA - How to Get Only Visible Rows (containing values) After Applying Filter

blueeye

New Member
Joined
Aug 20, 2014
Messages
25
Hi gals and guys,

here is my problem:

2d6uyaq.jpg


ConcatenateRange Function:
Code:
Function ConcatenateRange(ByVal cell_range As Range, _                    Optional ByVal seperator As String) As String


Dim cell As Range
Dim newString As String
Dim cellArray As Variant


Dim i As Long, j As Long
cellArray = cell_range.Value


For i = 1 To UBound(cellArray, 1)
    For j = 1 To UBound(cellArray, 2)
        If Len(cellArray(i, j)) <> 0 Then
            newString = newString & (seperator & cellArray(i, j))
        End If
    Next
Next


If Len(newString) <> 0 Then
    newString = Right$(newString, (Len(newString) - Len(seperator)))
End If


ConcatenateRange = newString


End Function

I would like to get ALL visible rows (containing values) after applying a filter, not only the row A4.

I have tried the following code, but this only output the A4 or more exactly, the rows until the hidden ones.
Code:
AllVisibleRows = ConcatenateRange(Range("A4:A65536").SpecialCells(xlCellTypeVisible))

How could I get all those filtered rows (A4,A6,etc.)?

Thank you in advance.

Regards,
blueeye
 
This is it:
Code:
If Len(cell.Text) Then CatVisible = CatVisible & sSep & cell.Value2

Well, you have just saved my day. How can I help you or donate?

Thank you both for your exhausting help.

Regards,
blueeye
 
Upvote 0

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I guess testing is occasionally warranted ...

Code:
Function CatVisible(r As Range, _
                    Optional sSep As String) As String
    Dim cell        As Range

    For Each cell In Intersect(r, r.Worksheet.UsedRange).SpecialCells(xlCellTypeVisible).Cells
        If Len(cell.Text) Then CatVisible = CatVisible & sSep & cell.Value2
    Next cell

    If Len(CatVisible) Then CatVisible = Mid(CatVisible, Len(sSep) + 1)
End Function
 
Upvote 0
Well, Thank you then. But I already do contribute regularly to another foundation. I just wanted to give you some bucks to "buy you a beer".
If you need any help with anything that I could handle myself, do not hesitate to contact me.

Thank you.
 
Upvote 0
@shg - I have found a new problem.
When I apply the filter and there is only one row in the output, I get the following error:
Run-time error '-2147417848 (80010108)':
Method 'Text' of object 'Range' failed

I use the following code and it allows the use of the button "SEND" only if the first row is not empty and also if there is only one row after the table's heading:
Code:
If ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas.Count > 1 Then
   fruit = ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Columns(1).Cells(1, 4)
ElseIf Not IsEmpty(Range("D4")) And Range("D3:D5").Rows.SpecialCells(xlCellTypeConstants).Count = 2 Then
   fruit = Range("D4")
Else
   MsgBox ("CHOOSE THE FRUIT")
   Exit Sub
End If

Don't you know where is the problem?

Thank you.
 
Upvote 0
Well, everything is working okay.
I was using:
Code:
dates = CatVisible(Range("O4:O65536").SpecialCells(xlCellTypeVisible), "%0A")
instead of
Code:
dates = CatVisible(Range("O4:O65536"), "%0A")
, cause the following code:
Code:
SpecialCells(xlCellTypeVisible)
is already contained in your CatVisible function.

I do apologize for any inconvenience or problems I have caused to you by the last post.
 
Upvote 0
What if I were about to change the title a bit?

"How to Get Only Visible Rows (containing values) After Applying Filter" to:
"How to Get Visible & Hidden Rows (containing values) After Applying Filter"

Is there any way to use CatVisible function along with hidden rows as well?

Thank you.
 
Upvote 0
I have tried using CatVisible and ConcatenateRange functions. They both works properly unless the column width is set to 0px (hidden column).

Is there any way to get this function working along with hidden columns as well?

Thank you.
 
Upvote 0

Forum statistics

Threads
1,215,424
Messages
6,124,817
Members
449,190
Latest member
rscraig11

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