I have found a new problem. Seems this function isn't grabbing all the data that falls within the criteria. For example,
There are 177 DoNot Call records, but only 129 have made it to the appropriate sheet. Also this it wasn't picking up Wrong Num records. The original data sheet has a sort on column I which is the filter column. When I sort asending Wrong Num code is at bottom. During the run it will ignore all Wrong Num records. However, when I sort descending wrong nums are included but Already Pl are short 9 records. Seems whatever code is at the bottom of the file is ignored or only part of the data is copied.
Any thoughts?
All my code for this macro
###################################
Public Sub import_Click()
' Open Text file, import to Excel
Dim myPath As String, myDate As String, savePath As String
' Set file location and file name
myDate = InputBox("Please enter filename: (mm-dd-yyyy.txt)", "Enter filename", Format(Date, "mm-dd-yyyy"))
'testing path
myPath = "C:\Documents and Settings\user\Desktop\Phonathon Comments\macro for chris\orig\"
savePath = "C:\Documents and Settings\user\Desktop\Phonathon Comments\macro for chris\new\"
'open tab delimited file
Workbooks.OpenText myPath & myDate & ".txt", Origin:=437, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=False _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2, 1), _
Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8, 1), Array(9, 1), _
Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), Array(15, 1), Array( _
16, 1)), TrailingMinusNumbers:=True
'autofit all rows
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
'hide the user form
runfrm.Hide
'process file
'===================================================================
'format sheet 1
Call Sort
Call Rowcount
Call ColumnFormat
Call Addsheet
Call test
'save workbook after all processing is complete
ActiveWorkbook.SaveAs savePath & myDate & ".xls", FileFormat:= _
xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
, CreateBackup:=False
'show the user form
runfrm.Show
End Sub
Private Sub Sort()
'sort by Comment Code Column I
Cells.Select
Selection.Sort Key1:=Range("I2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
'set col width and text wrap on G, H, K, & L
Private Sub ColumnFormat()
ActiveWindow.SmallScroll ToRight:=6
Range("G:G,H:H").Select
Range("H1").Activate
ActiveWindow.SmallScroll ToRight:=2
Range("G:G,H:H,K:K,L:L").Select
Range("L1").Activate
Selection.ColumnWidth = 50
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
'set column heading on Sheet 1
Range("H1").Select
ActiveCell.FormulaR1C1 = "OTHER"
Range("I1").Select
ActiveCell.FormulaR1C1 = "CODE"
Range("J1").Select
ActiveCell.FormulaR1C1 = "CALLER"
Range("A1").Select
End Sub
Private Sub Addsheet()
'add sheets to file for split function
Sheets.Add Type:=xlWorksheet, After:=Sheets(1)
Sheets.Add Type:=xlWorksheet, After:=Sheets(2)
Sheets.Add Type:=xlWorksheet, After:=Sheets(3)
'rename sheets
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "alumni_records"
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "supervisor_review"
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "other"
'make sheet 1 active for filter to begin
Sheets(1).Select
End Sub
Private Sub Rowcount()
'count rows before processing file, display in messagebox
Dim Rng As Range
Set Rng = Range("A2:A" & Range("A65536").End(xlUp).Row)
MsgBox WorksheetFunction.CountA(Rng) & " Records to process!"
End Sub
Sub test()
Dim DataRng As Range, PasteSheet As Worksheet
Dim myCriteria As Variant, i As Integer
'range of data--not including header row (row 1)
Set DataRng = Range("A2", Range("L65536").End(xlUp))
'an array that holds the terms that will be filtered for
myCriteria = Array("Deceased", "Disconnect", _
"Wrong Num", "Remove Lst", "DoNot Call", "No English", _
"Out Cntry", "Already Pl", "Yes Pledge", "Maybe Pledge", "No Pledge", "Spec Pldg", _
"Unsp Pldg")
Application.ScreenUpdating = False
With Rows(1)
.AutoFilter 'turn on autofilter on row 1
For i = LBound(myCriteria) To UBound(myCriteria)
.AutoFilter field:=9, Criteria1:=myCriteria(i) 'filter column I
Select Case myCriteria(i)
Case Is = "Deceased", "Disconnect", _
"Remove Lst", "DoNot Call", "Wrong Num"
Set PasteSheet = Sheets("alumni_records")
Case Is = "No English", "Out Cntry", "Already Pl", _
"Yes Pledge", "Maybe Pledge", "No Pledge", "Unsp Pldg", "Spec Pldg"
Set PasteSheet = Sheets("supervisor_review")
End Select
On Error Resume Next
'copy data visible in column G, paste to corresponding sheet
DataRng.SpecialCells(xlCellTypeVisible).Copy _
Destination:=PasteSheet.Range("A65536").End(xlUp).Offset(1, 0)
Next i
.AutoFilter 'turn off autofilter
End With
Application.ScreenUpdating = True
Sheets("alumni_records").Select
'add headings
Call Headings
Call columnfit
Range("A1").Select
Sheets("supervisor_review").Select
'add headings
Call Headings
Call columnfit
Range("A1").Select
Sheets(1).Select
Range("A1").Select
End Sub
Private Sub columnfit()
'format column width to autofit
Cells.Select
Selection.Columns.AutoFit
End Sub
Private Sub Headings()
'add column heading to all but sheet 1
Range("A1").Select
ActiveCell.FormulaR1C1 = "PROSPECT ID"
Range("B1").Select
ActiveCell.FormulaR1C1 = "LAST NAME"
Range("C1").Select
ActiveCell.FormulaR1C1 = "FIRST NAME"
Range("D1").Select
ActiveCell.FormulaR1C1 = "PHONE"
Range("E1").Select
ActiveCell.FormulaR1C1 = "STANDARD COMMENTS"
Range("F1").Select
ActiveCell.FormulaR1C1 = "FREE COMMENTS"
Range("G1").Select
ActiveCell.FormulaR1C1 = "EXTENDED COMMENTS"
Range("H1").Select
ActiveCell.FormulaR1C1 = "OTHER"
Range("I1").Select
ActiveCell.FormulaR1C1 = "CODE"
Range("J1").Select
ActiveCell.FormulaR1C1 = "CALLER"
Range("A1").Select
End Sub