mercredi 25 février 2015

How to autofilter column 1 and return related results in column 2

this is my first post. I am new to VBA and programming in general, and admittedly am still getting the hang of when to use variables and everything else. I am writing a basic VBA against a download file that can not be changed. Code is below



Sub KPIMacroFull()

Set sht = ThisWorkbook.Worksheets(Sheet1.Name)
Rows("1:2").Select
Selection.Delete Shift:=xlUp

ActiveCell.Offset(0, 9).Activate
Range("J:J").AutoFilter 1, 20


lr = Cells(Rows.Count, "J").End(xlUp).Row
If lr > 1 Then
Range("A2:A" & lr).SpecialCells(xlCellTypeVisible).EntireRow.Delete
End If


Cells.AutoFilter
Cells.AutoFilter


ActiveCell.Offset(0, 0).Activate
ActiveCell.Offset(0, 20).Activate


Range("AD1").EntireColumn.Insert
Range("AD1").Value = "Rush or Regular"
Range("A1:AK1").Columns.AutoFit
Range("AC:AC").AutoFilter 29, "D"


So basically what I want to do is autofilter column AC for values "D","K","Q","V","U",1,9. then in Column AD excel would return "Regular". For all other values in column AC (there are about 15 more classifications) I want excel to return "Rush". I am thinking a variable to set Regular to the above values and then going from there, but I am lost.


I checked a lot of other autofilter and VBA posts, but my questions seems to be more rudimentary and have not found anything too helpful.


Aucun commentaire:

Enregistrer un commentaire