I have a ton to learn about VBA and am struggling to figure out how I match information up from the column of another worksheet to the column in a newly added worksheet. I am trying to do this in a macro that sets up the new worksheet. Here is the macro as it is now:
Basically what I'd like to do is add something that worked like a vlookup copied down through all applicable cells in column M. The vlookup formula as I'd do it without VBA would be =VLOOKUP($A2,PREVIOUS!$A$2:$M$3034,13,FALSE), and then copied down through the necessary cells.
Any suggestions on how to do this, while taking into account changing numbers of rows to look up from and changing numbers of rows to bring data over to?
Code:
Dim ds As Range
Set ds = ActiveSheet.Range("A1").CurrentRegion
With ActiveSheet
Range("E:P,R:U,W:X,Z:Z,AE:AG,AI:IV").Select
Selection.Delete Shift:=xlToLeft
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AutoFilter
Cells.Select
Cells.EntireColumn.AutoFit
Application.EnableEvents = True
Selection.AutoFilter Field:=5, Criteria1:="FTNB"
Set ds = ds.Offset(1, 0).Resize(ds.Rows.Count - 1)
Set ds = ds.SpecialCells(xlCellTypeVisible)
ds.EntireRow.Delete
Set ds = ActiveSheet.Range("A1").CurrentRegion
Selection.AutoFilter Field:=5, Criteria1:="PTNB"
Set ds = ds.Offset(1, 0).Resize(ds.Rows.Count - 1)
Set ds = ds.SpecialCells(xlCellTypeVisible)
ds.EntireRow.Delete
Selection.AutoFilter Field:=5
Range("M1") = "DATE SEEN"
Range("M1").Font.Bold = True
Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AutoFilter
Selection.AutoFilter
Cells.EntireColumn.AutoFit
End With
ActiveSheet.Name = Format(Date, "mmddyy")
End Sub
Basically what I'd like to do is add something that worked like a vlookup copied down through all applicable cells in column M. The vlookup formula as I'd do it without VBA would be =VLOOKUP($A2,PREVIOUS!$A$2:$M$3034,13,FALSE), and then copied down through the necessary cells.
Any suggestions on how to do this, while taking into account changing numbers of rows to look up from and changing numbers of rows to bring data over to?