• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Add Date filter to Macro

Rafay Ahmed

New Member
Hi Everbody,
Below is a Macro, where I have to add Sorting of Date (from A to Z) before assigning Number to "xyz"

Also, attached is the sheet.

Thanks


Code:
Sub Filter_Assign_Values()

'Setup
Dim FilterStr As String
  FilterStr = "xyz"

'Select Worksheet 
Sheets("Payments").Select

'Clear Filter
On Error Resume Next
  ActiveSheet.ShowAllData

'Apply "Axel" Filter
Dim rng As Range
Dim lr As Long
  lr = Range("A" & Rows.Count).End(xlUp).Row
Set rng = Range("A5:F" & lr)
  rng.AutoFilter Field:=2, Criteria1:=FilterStr

'assign values to Filtereed data
Dim cl As Range
Dim x As Integer
Set rng = Range("F6:F" & lr)

  x = 1

For Each cl In rng.SpecialCells(xlCellTypeVisible)
  cl = "Comp-" & Format(x, "00")
  x = x + 1
Next cl

End Sub
 

Attachments

  • Workbook1.xlsx
    8.8 KB · Views: 3
Last edited by a moderator:
Rafay

a few issues

The file you provided doesn't have a Payments worksheet as required by teh macro?

Your code sets the Rng between Column A & Column F
But the file only has 3 columns of data?

I suspect you have sent us the wrong file?

Please review
 
Back
Top