Is there a solution for the following: I am getting the error in my vbscript: “Microsoft Excel: Autofilter Method of Range class failed”My Copying code doesn't copy entire row valueexcel replace function in access vbaVBA: Error when savings as CSV: Run-time error '424': Object requiredConditional copy Excel File-2 data to excel file-1?Extract IP Addresses in Microsoft Outlook using macrosExcel stops responding while executing loopHow to reference same dates between worksheets?Copy non-adjacent cells and paste transpose but not to an entire rowHow can I ignore an email attachment if missing from folderVBA not working (copy data from one file and paste to different workbook below last row of data)
Why is it that I have to play this note on the piano as A sharp?
Is Sanskrit really the mother of all languages?
How do draw effects during the discard phase work?
How many attacks exactly do I get combining Dual Wielder feat with Two-Weapon Fighting style?
Project Euler Problem 45
Did the Byzantines ever attempt to move their capital to Rome?
"syntax error near unexpected token" after editing .bashrc
What is the purpose of the rotating plate in front of the lock?
Is it right to use the ideas of non-winning designers in a design contest?
More than 3 domains hosted on IP
Dissuading my girlfriend from a scam
Passport - tiny rip on the edge of my passport page
Did the US Climate Reference Network Show No New Warming Since 2005 in the US?
Draw the ☣ (Biohazard Symbol)
Statistical closeness implies computational indistinguishability
1kV DC Circuit - Insulation on ground wire?
Owner keeps cutting corners and poaching workers for his other company
Could a British PM name the Opposition leader the next PM when they resign
Python reimplementation of Lost In Space by Tim Hartnell
Do 643,000 Americans go bankrupt every year due to medical bills?
Relationship between speed and cadence?
Putting future professor position on CV
Where on Earth is it easiest to survive in the wilderness?
How do you say "to hell with everything" in French?
Is there a solution for the following: I am getting the error in my vbscript: “Microsoft Excel: Autofilter Method of Range class failed”
My Copying code doesn't copy entire row valueexcel replace function in access vbaVBA: Error when savings as CSV: Run-time error '424': Object requiredConditional copy Excel File-2 data to excel file-1?Extract IP Addresses in Microsoft Outlook using macrosExcel stops responding while executing loopHow to reference same dates between worksheets?Copy non-adjacent cells and paste transpose but not to an entire rowHow can I ignore an email attachment if missing from folderVBA not working (copy data from one file and paste to different workbook below last row of data)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have gone through may threads. Still, I am getting the error. The data is valid. Please help.
'Option Explicit
'create the excel object
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Dim objWorkbook
Set objWorkbook = objExcel.Workbooks.Open("C:UsersPParkheDesktopJan-19 BT IOP1.xlsx")
Const xlUp = -4162
DeleteRowsWithAutofilter
Public Sub DeleteRowsWithAutofilter()
Dim wksData' As Worksheet
Dim lngLastRow 'As Long
Dim rngData 'As Range
'Set references up-front
Set wksData = objExcel.Worksheets("DATA")
wksdata.AutoFilterMode = False
'Identify the last row and use that info to set up the Range
With wksData
lngLastRow = .Range("B" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("A1:C9" & lngLastRow)
End With
'Here is where we use the .AutoFilter method to crush those
'annoying "Thumbs.db" and "Invoice.zip" rows
'Application.DisplayAlerts = False
With rngData
'Apply the Autofilter method to the first column of
'the range, using xlOr to select either
'"Thumbs.db" or "Invoice.zip"
.AutoFilter Field = 1, _
Criteria1="=2"', _
'Operator:=xlOr, _
'Criteria2:="Invoice.zip"
'Delete the visible rows while keeping the header
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
End With
'Application.DisplayAlerts = True
'Turn off the AutoFilter
With wksData
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
'Let the user know the rows have been removed
MsgBox "Damn son! Rows removed."
End Sub
objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
'save the existing excel file. use SaveAs to save it as something else
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
'Sub displayMessage()
' MsgBox "hello world!"
'End Sub
The script is not going to autofilter itself.
excel vba
add a comment |
I have gone through may threads. Still, I am getting the error. The data is valid. Please help.
'Option Explicit
'create the excel object
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Dim objWorkbook
Set objWorkbook = objExcel.Workbooks.Open("C:UsersPParkheDesktopJan-19 BT IOP1.xlsx")
Const xlUp = -4162
DeleteRowsWithAutofilter
Public Sub DeleteRowsWithAutofilter()
Dim wksData' As Worksheet
Dim lngLastRow 'As Long
Dim rngData 'As Range
'Set references up-front
Set wksData = objExcel.Worksheets("DATA")
wksdata.AutoFilterMode = False
'Identify the last row and use that info to set up the Range
With wksData
lngLastRow = .Range("B" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("A1:C9" & lngLastRow)
End With
'Here is where we use the .AutoFilter method to crush those
'annoying "Thumbs.db" and "Invoice.zip" rows
'Application.DisplayAlerts = False
With rngData
'Apply the Autofilter method to the first column of
'the range, using xlOr to select either
'"Thumbs.db" or "Invoice.zip"
.AutoFilter Field = 1, _
Criteria1="=2"', _
'Operator:=xlOr, _
'Criteria2:="Invoice.zip"
'Delete the visible rows while keeping the header
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
End With
'Application.DisplayAlerts = True
'Turn off the AutoFilter
With wksData
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
'Let the user know the rows have been removed
MsgBox "Damn son! Rows removed."
End Sub
objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
'save the existing excel file. use SaveAs to save it as something else
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
'Sub displayMessage()
' MsgBox "hello world!"
'End Sub
The script is not going to autofilter itself.
excel vba
Set rngData = .Range("A1:C9" & lngLastRow)is that9a typo?
– Tim Williams
Mar 28 at 6:25
Is that code within another procedure? You can'tSetobjects outside a procedure.
– Mark Fitzgerald
Mar 28 at 10:17
add a comment |
I have gone through may threads. Still, I am getting the error. The data is valid. Please help.
'Option Explicit
'create the excel object
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Dim objWorkbook
Set objWorkbook = objExcel.Workbooks.Open("C:UsersPParkheDesktopJan-19 BT IOP1.xlsx")
Const xlUp = -4162
DeleteRowsWithAutofilter
Public Sub DeleteRowsWithAutofilter()
Dim wksData' As Worksheet
Dim lngLastRow 'As Long
Dim rngData 'As Range
'Set references up-front
Set wksData = objExcel.Worksheets("DATA")
wksdata.AutoFilterMode = False
'Identify the last row and use that info to set up the Range
With wksData
lngLastRow = .Range("B" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("A1:C9" & lngLastRow)
End With
'Here is where we use the .AutoFilter method to crush those
'annoying "Thumbs.db" and "Invoice.zip" rows
'Application.DisplayAlerts = False
With rngData
'Apply the Autofilter method to the first column of
'the range, using xlOr to select either
'"Thumbs.db" or "Invoice.zip"
.AutoFilter Field = 1, _
Criteria1="=2"', _
'Operator:=xlOr, _
'Criteria2:="Invoice.zip"
'Delete the visible rows while keeping the header
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
End With
'Application.DisplayAlerts = True
'Turn off the AutoFilter
With wksData
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
'Let the user know the rows have been removed
MsgBox "Damn son! Rows removed."
End Sub
objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
'save the existing excel file. use SaveAs to save it as something else
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
'Sub displayMessage()
' MsgBox "hello world!"
'End Sub
The script is not going to autofilter itself.
excel vba
I have gone through may threads. Still, I am getting the error. The data is valid. Please help.
'Option Explicit
'create the excel object
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
'view the excel program and file, set to false to hide the whole process
objExcel.Visible = True
'open an excel file (make sure to change the location) .xls for 2003 or earlier
Dim objWorkbook
Set objWorkbook = objExcel.Workbooks.Open("C:UsersPParkheDesktopJan-19 BT IOP1.xlsx")
Const xlUp = -4162
DeleteRowsWithAutofilter
Public Sub DeleteRowsWithAutofilter()
Dim wksData' As Worksheet
Dim lngLastRow 'As Long
Dim rngData 'As Range
'Set references up-front
Set wksData = objExcel.Worksheets("DATA")
wksdata.AutoFilterMode = False
'Identify the last row and use that info to set up the Range
With wksData
lngLastRow = .Range("B" & .Rows.Count).End(xlUp).Row
Set rngData = .Range("A1:C9" & lngLastRow)
End With
'Here is where we use the .AutoFilter method to crush those
'annoying "Thumbs.db" and "Invoice.zip" rows
'Application.DisplayAlerts = False
With rngData
'Apply the Autofilter method to the first column of
'the range, using xlOr to select either
'"Thumbs.db" or "Invoice.zip"
.AutoFilter Field = 1, _
Criteria1="=2"', _
'Operator:=xlOr, _
'Criteria2:="Invoice.zip"
'Delete the visible rows while keeping the header
.Offset(1, 0).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Rows.Delete
End With
'Application.DisplayAlerts = True
'Turn off the AutoFilter
With wksData
.AutoFilterMode = False
If .FilterMode = True Then
.ShowAllData
End If
End With
'Let the user know the rows have been removed
MsgBox "Damn son! Rows removed."
End Sub
objExcel.DisplayAlerts = True
objExcel.ScreenUpdating = True
'save the existing excel file. use SaveAs to save it as something else
objWorkbook.Save
'close the workbook
objWorkbook.Close
'exit the excel program
objExcel.Quit
'release objects
Set objExcel = Nothing
Set objWorkbook = Nothing
'Sub displayMessage()
' MsgBox "hello world!"
'End Sub
The script is not going to autofilter itself.
excel vba
excel vba
edited Mar 28 at 6:14
Cody Gray♦
201k38 gold badges404 silver badges487 bronze badges
201k38 gold badges404 silver badges487 bronze badges
asked Mar 28 at 5:58
Pinakin ParkhePinakin Parkhe
1
1
Set rngData = .Range("A1:C9" & lngLastRow)is that9a typo?
– Tim Williams
Mar 28 at 6:25
Is that code within another procedure? You can'tSetobjects outside a procedure.
– Mark Fitzgerald
Mar 28 at 10:17
add a comment |
Set rngData = .Range("A1:C9" & lngLastRow)is that9a typo?
– Tim Williams
Mar 28 at 6:25
Is that code within another procedure? You can'tSetobjects outside a procedure.
– Mark Fitzgerald
Mar 28 at 10:17
Set rngData = .Range("A1:C9" & lngLastRow) is that 9 a typo?– Tim Williams
Mar 28 at 6:25
Set rngData = .Range("A1:C9" & lngLastRow) is that 9 a typo?– Tim Williams
Mar 28 at 6:25
Is that code within another procedure? You can't
Set objects outside a procedure.– Mark Fitzgerald
Mar 28 at 10:17
Is that code within another procedure? You can't
Set objects outside a procedure.– Mark Fitzgerald
Mar 28 at 10:17
add a comment |
1 Answer
1
active
oldest
votes
You are missing :
Change
Field = 1,Criteria1="=2"
to
Field:=1, Criteria1:="=2"
Also declare Const xlCellTypeVisible = 12 at the top like you did for xlUp
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391024%2fis-there-a-solution-for-the-following-i-am-getting-the-error-in-my-vbscript-m%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are missing :
Change
Field = 1,Criteria1="=2"
to
Field:=1, Criteria1:="=2"
Also declare Const xlCellTypeVisible = 12 at the top like you did for xlUp
add a comment |
You are missing :
Change
Field = 1,Criteria1="=2"
to
Field:=1, Criteria1:="=2"
Also declare Const xlCellTypeVisible = 12 at the top like you did for xlUp
add a comment |
You are missing :
Change
Field = 1,Criteria1="=2"
to
Field:=1, Criteria1:="=2"
Also declare Const xlCellTypeVisible = 12 at the top like you did for xlUp
You are missing :
Change
Field = 1,Criteria1="=2"
to
Field:=1, Criteria1:="=2"
Also declare Const xlCellTypeVisible = 12 at the top like you did for xlUp
answered Mar 28 at 6:24
Siddharth RoutSiddharth Rout
122k15 gold badges163 silver badges218 bronze badges
122k15 gold badges163 silver badges218 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55391024%2fis-there-a-solution-for-the-following-i-am-getting-the-error-in-my-vbscript-m%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Set rngData = .Range("A1:C9" & lngLastRow)is that9a typo?– Tim Williams
Mar 28 at 6:25
Is that code within another procedure? You can't
Setobjects outside a procedure.– Mark Fitzgerald
Mar 28 at 10:17