Hi all
I have written a macro for which the code is shown below.
Using excel 2007 but stored as .xls because an assistant user is gonig to use the workbook with excel2003.
The assistant user is experiencing an error titled "Object doesn't support this property or method". I only have a screenshot of this error message. Unfortunately, the assistant sits in a different geographical location so I'm unable to observe the error or replicate it on my side.
Compatibility checker in my excel shows taht there are NO ISSUES.
The macro runs perfectly on my computer.
Macro does the following (1) opens a .csv file, (2) copies all the content from the sheet, (3) switches back to my workbook, (4) inserts a new sheet, (5) pastes the data, (6) selects range (7) runs autofilter on 2 criteria (8) copies the filtered results (9) adds new sheet and pastes the copied data from (8).
From the screenshot that was supplied to me, I can see that the code is executing up to this line, and then the error msg is displayed:
'LastRow definition for imported bank statement
LastRow = Sheets("Import").Cells(Rows.Count, "A").End(xlUp).Row
This is where the error msgbox pops up.
The screenshot shows all cells highlighted. If I run the code up to cursor at the end of this line, then on my screen the Excel spreadsheet looks the same as the screenshot.
The next line of code goes on to the Autofilter.
Columns("A:I").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$I$" & LastRow).AutoFilter Field:=3, Criteria1:="="
ActiveSheet.Range("$A$1:$I$" & LastRow).AutoFilter Field:=2, Criteria1:="<>"
The screenshot does not show Columns A-I being selected.
So I'm guessing that this Autofilter type is not supported in Excel 2003? But I can't seem to find any more info on internet search.
Have checked Microsoft website here as advised by MarvinP.
Also used Bing search but with no success.
Here is the entire code -
Dim LastRow As Long
'used to open file from dialog box
Dim FilesToOpen As Variant
On Error GoTo ErrHandler
'dialog box to check with user if file stored in HDD
Answer = MsgBox("Have you stored bank statement file as .csv on your computer ?", vbYesNo, "IMPORTING STANDARD BANK - BANK STATEMENT FILE")
If Answer = vbNo Then
MsgBox ("First store bank statement as .csv on your computer")
End If
'dialog box to select file to incorporate
FilesToOpen = Application.GetOpenFilename _
(filefilter:="CSV_Bankstatement* Files (*.CSV), *.csv", FilterIndex:=1, _
MultiSelect:=False, Title:="File to Import")
If TypeName(FilesToOpen) = "Boolean" Then
MsgBox "No Files were selected"
GoTo ExitHandler
End If
'Open file and Copy sheets from selected workbook
Workbooks.Open Filename:=FilesToOpen
'Code re-written at this point to accommodate excel-2003 users
'Copy contents from .csv file into new sheet on workbook
Cells.Select
Selection.Copy
ThisWorkbook.Activate
Sheets.Add
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Rename sheet and colour tab
ActiveSheet.Name = "Import"
With ActiveWorkbook.Sheets("Import").Tab
.Color = 5287936
.TintAndShade = 0
End With
'Dim LastRow definition for imported bank statement
LastRow = Sheets("Import").Cells(Rows.Count, "A").End(xlUp).Row
'apply filters
Columns("A:I").Select
Selection.AutoFilter
ActiveSheet.Range("$A$1:$I$" & LastRow).AutoFilter Field:=3, Criteria1:="="
ActiveSheet.Range("$A$1:$I$" & LastRow).AutoFilter Field:=2, Criteria1:="<>"
Range("A1:I" & LastRow).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
'Paste to new sheet
Sheets.Add
ActiveSheet.Name = "Norefs"
Range("A5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
With ActiveWorkbook.Sheets("Norefs").Tab
.Color = 5287936
.TintAndShade = 0
End With
Range("A1").Select
ActiveCell.FormulaR1C1 = "TRAVELSHOP RECONCILIATION"
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveCell.FormulaR1C1 = _
"Items on bank statement with no invoice or order numbers"
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.Font.Bold = True
With Selection.Font
.Name = "Calibri"
.Size = 14
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ThemeColor = xlThemeColorLight1
.TintAndShade = 0
.ThemeFont = xlThemeFontMinor
End With
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.Font.Bold = True
'turn off autofilters
Worksheets("Import").Select
Selection.AutoFilter
Range("A1").Select
Worksheets("Norefs").Select
'close source file
Application.GetSaveAsFilename
MsgBox ("Reports now created. Remember to close source file")
'exit handler
ExitHandler:
Exit Sub
'error handler
ErrHandler:
MsgBox Err.Description
Resume ExitHandler
End Sub
Any suggestions?
Bookmarks