Hello,
My macro works but can take up to 5 minutes or more to finish up. Is there a better way to do what I have below? The table creation goes quickly it is when it goes through it to delete what it doesn't need that slows it down. I am using excel 2013, and most of my experience with vba comes from watching the recorder so I'm wandering into unfamiliar territory.
Thank you
Sub Psudo()
' First Creates a table
Dim Tbl As ListObject
Set Tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
Tbl.TableStyle = "TableStyleMedium2"
' Selects and renames the Table to DashTable
Columns("A:I").Select
ActiveSheet.ListObjects(1).Name = "PsudoTbl"
' Clears out the old fill in the cells so the table style shows through
Range("PsudoTbl[#All]").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' FormatText Macro
Range("PsudoTbl[CASE_SSN]").Select
Selection.NumberFormat = "@"
' Delete rows if not a "P"
Dim LastRow As Integer
Dim n As Long
Dim DestinationRow As Integer
Dim CellValue As String
LastRow = Worksheets("Psudo").Range("A65536").End(xlUp).Row
For n = LastRow To 2 Step -1
CellValue = Worksheets("Psudo").Range("A" & n)
If Left(CellValue, 1) <> "P" Then
Worksheets("Psudo").Range("A" & n & ":Y" & n).EntireRow.Delete xlUp
ElseIf Left(CellValue, 1) = "P" Then
CellValue = Right(CellValue, 4)
Worksheets("Psudo").Range("A" & n) = CellValue
End If
Next n
End Sub
My macro works but can take up to 5 minutes or more to finish up. Is there a better way to do what I have below? The table creation goes quickly it is when it goes through it to delete what it doesn't need that slows it down. I am using excel 2013, and most of my experience with vba comes from watching the recorder so I'm wandering into unfamiliar territory.
Thank you
Sub Psudo()
' First Creates a table
Dim Tbl As ListObject
Set Tbl = ActiveSheet.ListObjects.Add(xlSrcRange, Selection, , xlYes)
Tbl.TableStyle = "TableStyleMedium2"
' Selects and renames the Table to DashTable
Columns("A:I").Select
ActiveSheet.ListObjects(1).Name = "PsudoTbl"
' Clears out the old fill in the cells so the table style shows through
Range("PsudoTbl[#All]").Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
' FormatText Macro
Range("PsudoTbl[CASE_SSN]").Select
Selection.NumberFormat = "@"
' Delete rows if not a "P"
Dim LastRow As Integer
Dim n As Long
Dim DestinationRow As Integer
Dim CellValue As String
LastRow = Worksheets("Psudo").Range("A65536").End(xlUp).Row
For n = LastRow To 2 Step -1
CellValue = Worksheets("Psudo").Range("A" & n)
If Left(CellValue, 1) <> "P" Then
Worksheets("Psudo").Range("A" & n & ":Y" & n).EntireRow.Delete xlUp
ElseIf Left(CellValue, 1) = "P" Then
CellValue = Right(CellValue, 4)
Worksheets("Psudo").Range("A" & n) = CellValue
End If
Next n
End Sub