How to Filter a column by text which has blank space in start

Sachin2k6

Active Member
Joined
Mar 3, 2012
Messages
369
Hi friends,
i have a data column in excel which has text containing blank space in start in some cells. how can i filter these cells which has text containing blank space in start.
 
Would a VBA solution work for you?

If yes, then try this

I am assuming that the data is in Col "A" of "Sheet1". Change the code below accordingly.

VBA Code:
Option Explicit

Sub Sample()
    Dim ws As Worksheet
    Dim lRow As Long, i As Long
    Dim FilteredRange As Range
  
    '~~> Change this to the relevant worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1")
  
    With ws
        .AutoFilterMode = False
      
        '~~> Find last row in Col A
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row
      
        '~~> Identify the rows that needs to be hidden
        For i = 2 To lRow
            If Left(.Range("A" & i).Value2, 1) <> " " Then
                If FilteredRange Is Nothing Then
                    Set FilteredRange = .Rows(i)
                Else
                    Set FilteredRange = Union(.Rows(i), FilteredRange)
                End If
            End If
        Next i
      
        '~~> Hide rows if applicable
        If Not FilteredRange Is Nothing Then FilteredRange.EntireRow.Hidden = True
    End With
End Sub

View attachment 56024
Thank you so much.
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Thank you so much.

Your question was to filter the columns. The chosen solution in fact does not filter the column as such but hides the irrelevant rows. It is the same visual result of course but you don't have the AutoFilter option at the top to then unhide the hidden rows. Did you try the other suggestions too?
 
Upvote 0
My purpose has solved with your code. Thanks.
Your question was to filter the columns. The chosen solution in fact does not filter the column as such but hides the irrelevant rows. It is the same visual result of course but you don't have the AutoFilter option at the top to then unhide the hidden rows. Did you try the other suggestions too?
 
Upvote 0

Forum statistics

Threads
1,214,814
Messages
6,121,711
Members
449,049
Latest member
THMarana

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