So, I've done last row autofills in VBA plenty of times, but for some reason this is causing an issue today. I understand why, but can't figure out the solution.
I am copying data (in this example there is 3700 rows) and pasting to a new sheet only the VISIBLE data after i filter to the critera: NEW. The NEW data contains only 129 rows of the 3700 and is pasted in this other tab called "New Unauth". However, when I autofill to Last Row, instead of it going to row 129 and ending, it continues to 3700. It is reading that there is data in rows 130 - 3700 even when there isnt. Obviously, my copy job isn't doing its job correctly. Is there any way around this?
If anybody could help I would greatly appreciate it! Thanks in advance! I'm sure it's something easy that I am missing.
I am copying data (in this example there is 3700 rows) and pasting to a new sheet only the VISIBLE data after i filter to the critera: NEW. The NEW data contains only 129 rows of the 3700 and is pasted in this other tab called "New Unauth". However, when I autofill to Last Row, instead of it going to row 129 and ending, it continues to 3700. It is reading that there is data in rows 130 - 3700 even when there isnt. Obviously, my copy job isn't doing its job correctly. Is there any way around this?
Code:
Sub Unauth_Ded()
Dim LR As Long
LR = Range("B" & Rows.Count).End(xlUp).Row
Selection.AutoFilter Field:=12, Criteria1:="NEW"
[B]Selection.SpecialCells(xlCellTypeVisible).Select[/B]
[B] Selection.Copy[/B]
Sheets("New Unauth").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Cells.Select
Cells.EntireColumn.AutoFit
Columns("A:A").Select
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Range("A2").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[1],'CA Codes'!R1C1:R32C2,2,FALSE)"
Range("A2").Select
[B]Selection.AutoFill Destination:=Range("A2:A" & LR)[/B]
[B]Columns("A:A").EntireColumn.AutoFit[/B]
Range("A1").Select
ActiveCell.FormulaR1C1 = "Analyst"
Range("A1").Select
With Selection.Interior
.ColorIndex = 15
.Pattern = xlSolid
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Sheets("New Detail").Select
ActiveSheet.ShowAllData
End Sub
If anybody could help I would greatly appreciate it! Thanks in advance! I'm sure it's something easy that I am missing.