Loop Through Autofilter Value

marka87uk

Board Regular
Joined
Mar 24, 2007
Messages
247
Hi,

The current code I have makes a directory named the current criteria, but please can you show me how to loop through each autofilter value and create a directory for each one?

Many thanks. :)

Code:
Sub CreateBranchDirectories()

' Get Current Criteria
With ActiveSheet
  If .AutoFilterMode Then
    With .AutoFilter.Filters(1)
      If .On Then c1 = .Criteria1:
    End With
  End If
End With

' c1 = Current Criteria (Replace "=")
c1 = Replace(c1, "=", "")

' Make Directories
MkDir "Y:\Directories\" & c1
        
End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Solved my own problem... don't know why I didn't think of doing it without an autofilter! :/

Code:
Sub CreateBranchDirectories()

Dim BranchList As Range, Branch As Object
Set BranchList = Range("A2:A1281")
     
For Each Branch In BranchList
    If IsEmpty(Branch) Then
    Exit Sub
    End If
    cBranch = Branch.Value
    MsgBox cBranch
Next
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,290
Members
452,902
Latest member
Knuddeluff

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