VBA Filter for Columns instead of Rows

VBA Filter for Columns instead of Rows

Dr. Gerard Verschuuren

8 лет назад

23,367 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@chenryjenkins7300
@chenryjenkins7300 - 27.01.2021 22:50

Dude never responds

Ответить
@advent7324
@advent7324 - 03.10.2020 15:09

Nice, but pretty useless for viewers if you don't share the sub code ! :(

Ответить
@gabrieldesiqueirabrito3459
@gabrieldesiqueirabrito3459 - 23.08.2020 01:22

'PART 1 MODULO CODE

Sub FillFilters() 'with sortcut
Dim oRange As Range, l As Long, r As Long, c As Long, sFilter As String, arr As Variant, sTemp As String, bDone As Boolean
If Range("A1") = "Filters" Then Exit Sub
Range("A2").EntireColumn.Insert
Set oRange = Sheet9.Range("A2").CurrentRegion
With oRange
.Cells.EntireColumn.Hidden = False
.Cells(1, 1) = "Filters"
For r = 2 To .Rows.Count
For c = 3 To .Columns.Count
If WorksheetFunction.CountIf(Range(Cells(r, 3), Cells(r, c)), Cell(r, c)) = 1 Then
sFilter = sFilter & "," & Cells(r, c)
End If
Next c
arr = Split(sFilter, ",")
Do
bDone = True
For I = 1 To UBound(arr) - 1
If arr(I) > arr(I + 1) Then
bDone = False: sTemp = arr(I): arr(I) = arrr(I + 1): arr(I + 1) = sTemp
End If
Next I
Loop While bDonw = False
sFilter = Join(arr, ",")
With .Cells(r, I).Validation
.Delete
.Add Type:=xiValidateList, Formula1:="-" & sFilter & ",Blanks"
.InCellDropdown = True
End With
sFilter = ""
Next r
.Cells.EntireColumn.Hidden = False
End With


End Sub

Sub DeleteFilters() 'with shortcut
If Range("A1") = "Filters" Then
Cells.EntireColumn.Hidden = False
Range("A1").EntireColumn.Delete
Range("A1").Select
End If

End Sub

Sub Filtering(oFIlter As Range)
Dim oRange As Range, sCell As String, r As Long, c As Long, iRow As Long, iCount As Long
Set oRange = Sheet5.Range("A2").CurrentRegion
sCell = oFIlter.Value
If sCell = "Filters" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "-" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "Blanks" Then oRange.Cells.EntireColumn.Hidden = False: sCell = ""
oRange.Cells.EntireColmn.Hidden = False
iRow = oFIlter.Row
With oRange
For c = 3 To .Columns.Count
If .Cells(iRow, c) <> sCell Then
.Cell(iRow, c).EntireColumn.Hidden = True
Else
iCount = iCount + 1
End If
Next c
MsgBox iCount & " columns for row " & iRow
End With





End Sub

Ответить
@AB-hi6wg
@AB-hi6wg - 25.06.2020 05:15

Thanks Dr Gerard, This is really cool!

Ответить
@neerajmaurya8440
@neerajmaurya8440 - 25.12.2019 14:18

we have a query can i change column data to another column data after using autofilter in vba

Ответить
@emmanuelramos5158
@emmanuelramos5158 - 18.07.2019 22:34

Anybody wrote the code manually ? Would like to have it :)

Ответить
@jtb000
@jtb000 - 10.06.2019 10:12

========================
MODULE CODE
========================
Option Explicit
Sub FillFifters() 'with shortcut
Dim oRange As Range, i As Long, r As Long, c As Long, sFilter As String, arr As Variant, sTemp As String, bDone As Boolean
If Range("A1") = "Filters" Then Exit Sub
Range("A2").EntireColumn.Insert
Set oRange = Sheet11.Range("A2").CurrentRegion
With oRange
.Cells.EntireColumn.Hidden = False
.Cells(1, 1) = "Filters"
For r = 2 To .Rows.Count
For c = 3 To .Columns.Count
If WorksheetFunction.CountIf(Range(Cells(r, 3), Cells(r, c)), Cells(r, c)) = 1 Then
sFilter = sFilter & "," & Cells(r, c)
End If
Next c
arr = Split(sFilter, ",")
Do
bDone = True
For i = 1 To UBound(arr) - 1
If arr(i) > arr(i + 1) Then
bDone = False: sTemp = arr(i): arr(i) = arr(i + 1): arr(i + 1) = sTemp
End If
Next i
Loop While bDone = False
sFilter = Join(arr, ",")
With .Cells(r, 1).Validation
.Delete
.Add Type:=xlValidateList, Formula1:="-" & sFilter & ", Blanks"
.InCellDropdown = True
End With
sFilter = ""
Next r
.Cells.EntireColumn.Hidden = False
End With
End Sub
Sub DeleteFilters() 'with shortcut
If Range("A1") = "Filters" Then
Cell.EntireColumn.Hidden = False
Range("A1").EntireColumn.Delete
Range("A1").Select
End If
End Sub
Sub Filtering(oFilter As Range) 'in worksheet event
Dim oRange As Range, sCell As String, r As Long, c As Long, iRow As Long, iCount As Long
Set oRange = Sheet11.Range("A2").CurrentRegion
sCell = oFilter.Value
If sCell = "Filters" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "-" Then oRange.Cells.EntireColumn.Hidden = False: Exit Sub
If sCell = "Blanks" Then oRange.Cells.EntireColumn.Hidden = False: sCell = ""
oRange.Cells.EntireColumn.Hidden = False
iRow = oFilter.Row
With oRange
For c = 3 To .Columns.Count
If .Cells(iRow, c) <> sCell Then
.Cells(iRow, c).EntireColumn.Hidden = True
Else
iCount = iCount + 1
End If
Next c
MsgBox iCount & " columns for row " & iRow
End With
End Sub


====================
SHEET1 CODE
====================
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") <> "Filters" Then Exit Sub
If Target Is Nothing Then Exit Sub
If Target.Column = 1 Then Filtering Target
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Range("A1") <> "Filters" Then Exit Sub
If Target Is Nothing Then Exit Sub
If Target.Column <> 1 Then Exit Sub
If Target.Cells.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
Filtering Target
End Sub

Ответить
@jammers7279
@jammers7279 - 16.05.2019 13:12

When i press ctrl+shift+F it opens fonts.... Am i doing something wrong?

Ответить
@cospinan
@cospinan - 08.05.2019 13:34

Excellent video, not only to do the filtering but to learn how to do the VBA programming. do you have VBA tutorials in this way... would be great

Ответить
@MarkFreemanYVR
@MarkFreemanYVR - 31.10.2018 20:30

WIsh the code was pated here. Typing this in by hand will bring me back to the mid 80's typing in code for my VIC-20 from the back of a magazine.


If I do it, I'll paste the code here since I like the way this seems to work.

Ответить
@tVideoUTube
@tVideoUTube - 12.09.2018 05:56

Nice tip, anyone ever get code for this?? - it seems the author is oblivions to comments and the concept of sharing via pastebin, etc.

Ответить
@mariekevanbrussel557
@mariekevanbrussel557 - 05.08.2018 00:21

Is there a way to give the possibility to select multiple values to filter on for a row (ex. I want to show all the values that are equal to 2 and 3 in a row)?

Ответить
@atanuchaterjee4149
@atanuchaterjee4149 - 27.03.2018 17:59

Very Helpful video, Can you please share the code as well.

Ответить
@audi22885
@audi22885 - 21.01.2018 08:42

Thanks. That was really helpful.

Ответить
@yousrar3025
@yousrar3025 - 06.12.2017 14:31

Hi, this is a very interesting video. Can you please share the module code. Thanks

Ответить
@JAMOABGLP
@JAMOABGLP - 27.06.2017 15:03

Hi is it possible to make the filter selective for one row? So that I can filter different Columns for example all columns in that row, that have 30 and 44 and 60 (And so on) in it? would be really great! thank you!

Ответить
@kinsinglim
@kinsinglim - 26.05.2017 12:53

Hi I have code it as per your instruction, but the dropbox do not appear on my spread sheet. Can you help advise?

Ответить
@ShahadatHossain-dn7ho
@ShahadatHossain-dn7ho - 27.02.2017 11:06

Can i have the code please...

Ответить