Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-07-2018, 07:01 PM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default Excel Macro: Run-time Error '91'

I keep on having the same error on all my forms with the search button.


Run-time Error '91'
Object variable or With block variable not set

and it shows that the error is on ListBox ( see attached image )

Can anyone help me?

Thanks
Attached Images
File Type: png 2.PNG (42.6 KB, 40 views)
Reply With Quote
  #2  
Old 06-10-2018, 04:53 AM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

This is my code and you deleted/missed out what to do if LBRS is nothing, something along the lines of:
If LBRS Is Nothing Then Set LBRS = .Range("A2")
Reply With Quote
  #3  
Old 06-10-2018, 07:20 PM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default

yes it is your code, I've been finding out what is the problem and I don't know what it is.
I already added the code if nothing but the same error shows
Reply With Quote
  #4  
Old 06-11-2018, 01:08 AM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

When you debug, and that line is highlighted as in your picture, what's showing in the Value column of the Locals pane of the VBE for LBRS?
If it's not showing Nothing or Empty, then in the Immediate pane, type:
?LBRS.address
and press Enter. What's the result?


It would be easier to help you if you could provide a file where this error occurs - sure, desensitize the file and remove unnecessary sheets/code, but do ensure that the error still occurs before posting it here.
Reply With Quote
  #5  
Old 06-11-2018, 01:18 AM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default

Here is the file
Attached Files
File Type: xlsm Book1.xlsm (27.6 KB, 7 views)
Reply With Quote
  #6  
Old 06-11-2018, 03:01 AM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

See attached.
LBRS was Empty/Nothing at that stage in the code. I've reinstated that line.

Headers in Report B, if present, should exactly match those in Sheet1
Headers should only be on one row. There should be no duplicate headers in Sheet1.

I've copied the headers from Report B to Sheet1 but really I should have reduced the headers on Sheet1 to 1 row and re-written the code which puts the headers in Report B to match those in Sheet1. I was lazy.
You have to get the Control names exactly right in the code. Corrected.
At least now it works to a degree, over to you to add the ifs and buts, checks etc.
For instance if someone chooses None from your dropdown for the Adhesive Type, are there entries in that column with the literal string None in them?, or are you hoping to show results for when there is nothing in those cells? There's a putative line in there which you can remove if I've got this wrong.
There are a few commented-out lines of code which you might end up needing to use.
Try to avoid On Error Resume Next too much unless you know an error might be thrown and why, otherwise it hides errors while debugging.
The code:
Code:
On Error Resume Next
Set newsht = Sheets("Report B")
On Error GoTo 0
has the On Error Resume Next because the next line will always throw an error if the sheet doesn't exist, but the On Error Goto 0 returns error reporting to normal straight after.
Attached Files
File Type: xlsm msofficeforums39312.xlsm (30.2 KB, 10 views)
Reply With Quote
  #7  
Old 06-13-2018, 07:06 PM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default

Thank you
if all the products show when its not supposed to, is it something wrong with the
SceSht.Range(A1)?
Reply With Quote
  #8  
Old 06-13-2018, 09:57 PM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Quote:
Originally Posted by andxie View Post
if all the products show when its not supposed to, is it something wrong with the SceSht.Range(A1)?
I have no idea.
Under what circumstances? Attach your current file.
Reply With Quote
  #9  
Old 06-13-2018, 11:32 PM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default

See attached file.

The Sheet 2 is the one I am talking about, when I enter "1" on Tag Size Width, it shows all the products instead of only showing product B.
Attached Files
File Type: xlsm msofficeforums39312_revised.xlsm (32.6 KB, 9 views)
Reply With Quote
  #10  
Old 06-14-2018, 03:22 AM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

Again,
Quote:
Originally Posted by p45cal View Post
Headers in Report C, if present, should exactly match those in Sheet2
They don't have to be in the same order.
An example of how yours differ:
On sheet Sheet2:

and on Report C:

Last edited by p45cal; 06-14-2018 at 05:43 AM.
Reply With Quote
  #11  
Old 06-20-2018, 08:06 PM
andxie andxie is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2013
Novice
Excel Macro: Run-time Error '91'
 
Join Date: May 2018
Posts: 15
andxie is on a distinguished road
Default

I already checked, but still it shows all the products after clicking the search button. Also I keep on getting the same error (See attached image) on my other sheet. Excel Sheet is attached.
Attached Images
File Type: png error.PNG (7.0 KB, 17 views)
Attached Files
File Type: xlsm Book1.xlsm (23.8 KB, 9 views)
Reply With Quote
  #12  
Old 06-21-2018, 01:12 AM
Debaser's Avatar
Debaser Debaser is offline Excel Macro: Run-time Error '91' Windows 7 64bit Excel Macro: Run-time Error '91' Office 2010 32bit
Competent Performer
 
Join Date: Oct 2015
Location: UK
Posts: 221
Debaser will become famous soon enough
Default

The headers on the report sheet don't match the headers on the data sheet - e.g. misspellings of the word "without" on the data sheet, and extra spaces in some headers. I suggest you copy the first row of headers from the data sheet and paste them into the report sheet.
Reply With Quote
  #13  
Old 06-21-2018, 05:22 AM
p45cal's Avatar
p45cal p45cal is offline Excel Macro: Run-time Error '91' Windows 10 Excel Macro: Run-time Error '91' Office 2016
Expert
 
Join Date: Apr 2014
Posts: 867
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

The code doesn't expect to see multiple tables on Sheet1; for .currentregion to work properly here, every table needs to be separated from its neighbour by at least one completely blank/empty row. Deleting the text Table 4 in cell A22 satisfied that in this case.


Still, headers don't match:
You have Product Number in cell A23 of Sheet1, but Product in cell A1 of the Report sheet.
You have a trailing space in cell B23 of Sheet1, but none in cell C1 of the Report sheet.


In the userform you have a textbox called txtResMinC, but you have in the same place on the userform, another textbox called ResMinC, worse, you have a variable in the code ResMinC! I deleted the textbox ResMinC from the Userform.
Attached Files
File Type: xlsm msofficeforums39312 v2.xlsm (26.9 KB, 8 views)
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2010 Run-Time error 4198 with Insert Picture with Caption and Fram Macro jstills116 Word VBA 0 06-24-2016 07:46 AM
Help Please: New VBA user trying to use a macro to split Mail Merge documents. Two Run-Time Error zipit189 Word VBA 7 03-18-2015 01:13 PM
Excel Macro: Run-time Error '91' Shift Excel Cell after executing a macro for second time LearningMacro Excel Programming 2 01-08-2015 03:05 PM
Excel Macro: Run-time Error '91' Run Time Error 4248 when opening Word Doc from Excel CIF Excel Programming 12 02-21-2014 02:27 PM
Excel Macro: Run-time Error '91' Run-time Error 5174: Open Word Documents from Excel tinfanide Excel Programming 3 10-01-2013 07:35 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:25 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft