I have a table. The first column called 'Category' is blank, I need to filter by 'BusinessType' column then fill in 'category' column based on various criteria (values in other columns).
My code partly works but these are my problems:
1. The label 'category' is changed along with the other visible cells.
2. When there is no 'Business Type' = "VAS" results in the filter, it fills in all 65K rows with my value instead of just skipping the procedure and moving on to the next filter value.
Here is my code:
Sub categories()
'Fill in Category for Business Type VAS
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="VAS"
If Range("B1").CurrentRegion.SpecialCells(xlCellTypeVisible).End(xlDown).Address = "$B$65536" Then
Selection.AutoFilter
Else
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="VAS"
Range("B1").Select
Range("B1").End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.SpecialCells(xlCellTypeVisible).Value = "VAS"
Range("B1").CurrentRegion.AutoFilter
End If
'Fill in Category for Business Type AIR
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="AIR"
If Range("B1").CurrentRegion.SpecialCells(xlCellTypeVisible).End(xlDown).Address = "$B$65536" Then
Selection.AutoFilter
Else
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="AIR"
Range("B1").Select
Range("B1").End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.SpecialCells(xlCellTypeVisible).Value = "AIR"
Range("B1").CurrentRegion.AutoFilter
End If
My code partly works but these are my problems:
1. The label 'category' is changed along with the other visible cells.
2. When there is no 'Business Type' = "VAS" results in the filter, it fills in all 65K rows with my value instead of just skipping the procedure and moving on to the next filter value.
Here is my code:
Sub categories()
'Fill in Category for Business Type VAS
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="VAS"
If Range("B1").CurrentRegion.SpecialCells(xlCellTypeVisible).End(xlDown).Address = "$B$65536" Then
Selection.AutoFilter
Else
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="VAS"
Range("B1").Select
Range("B1").End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.SpecialCells(xlCellTypeVisible).Value = "VAS"
Range("B1").CurrentRegion.AutoFilter
End If
'Fill in Category for Business Type AIR
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="AIR"
If Range("B1").CurrentRegion.SpecialCells(xlCellTypeVisible).End(xlDown).Address = "$B$65536" Then
Selection.AutoFilter
Else
Range("B1").CurrentRegion.AutoFilter Field:=3, Criteria1:="AIR"
Range("B1").Select
Range("B1").End(xlDown).Select
ActiveCell.Offset(0, -1).Select
Range(Selection, Selection.End(xlUp)).Select
Selection.SpecialCells(xlCellTypeVisible).Value = "AIR"
Range("B1").CurrentRegion.AutoFilter
End If