Excel 2007 Vba Runtime Error 91
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs
Vba Runtime Error 91 Object Variable Or With Block Variable Not Set
Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community run-time error '91' in excel macro of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up simple vba code gives me run time how to fix runtime error 91 object variable not set error 91 object variable or with block not set up vote 15 down vote favorite So I have a simple little macro/sub defined when a command button is clicked. The problem is it gives me: Run Time Error '91' : Object Variable or With Block
Object Variable Or With Block Variable Not Set Vba
not Set My code is: Dim rng As Range rng = Sheet8.Range("A12") '<< ERROR here rng.Value2 = "1" I just want to set Cell "A12" in Sheet8. Thanks! excel vba excel-vba excel-2007 share|improve this question edited Jul 10 '14 at 13:00 Fionnuala 77.1k665110 asked Mar 12 '11 at 9:44 gideon 15k54893 I'm sure there is a Sheet8 and there is certainly a cell A12 the sheet. Maybe its the syntax? Should it be "A" and "12" separately? –gideon Mar 12 '11 at 9:49 add a comment| 1
Vba Run Time Error 91
Answer 1 active oldest votes up vote 23 down vote accepted You need Set with objects: Set rng = Sheet8.Range("A12") Sheet8 is fine. Sheet1.[a1] share|improve this answer answered Mar 12 '11 at 9:53 Fionnuala 77.1k665110 +1 thanks doesn't gimme an error but doesn't set the A12 Cell value either? Should it be rng.Value or rng.Formula doesn't work either? –gideon Mar 12 '11 at 9:58 lol! ok now Set rng.Value2 = "1" Gives me a runtime error 424 –gideon Mar 12 '11 at 10:00 @giddy I am back :) You only use Set to set a variable to an object. The code you posted works fine for me with the addition of Set, as per my answer. Does Sheet8 exist? Do not forget I can rename Sheet3 as Sheet8 but it is still Sheet3. Do not confuse the object Sheet8 with the sheet named Sheet8. –Fionnuala Mar 12 '11 at 14:18 BTW You do not need quotes for numbers, but that has nothing to do with the problem. –Fionnuala Mar 12 '11 at 14:19 @Remou aha! So it works at my home machine! And i see I can add an excel form control and an ActiveX Button but it works with both! I guess I probably did something silly at the work machine! Thanks so much! =D –gideon Mar 12 '11 at 14:27 | show 1 more comment Your Answer draft saved draft discarded Sign up or log in Sign up using Google Sign up using Facebook Sign up using Email and Password Post a
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us runtime error 91 windows 7 Learn more about Stack Overflow the company Business Learn more about hiring developers
Object Variable Or With Block Variable Not Set Excel 2010
or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow object variable or with block variable not set vb6 Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up VBA Run time error 91. Trouble setting object http://stackoverflow.com/questions/5281759/simple-vba-code-gives-me-run-time-error-91-object-variable-or-with-block-not-set variable up vote 0 down vote favorite I don't think the answer is too complicated, I must just be missing something basic. To give context, the code and this macro were written by an employee who was no longer working here when I started. I have just used it a number of times on a monthly basis and it suddenly gave me an error today when I http://stackoverflow.com/questions/22840227/vba-run-time-error-91-trouble-setting-object-variable attempted to run the VBA script. It gives me the standard Run Time Error 91 (Object variable or block variable not set). The code specifically is: Dim DataBook As Workbook Set DataBook = Workbooks.Open(Import_File_Path) DataBook.Worksheets("Sheet1").Name = "Database" Application.DisplayAlerts = False Tool.Worksheets("Database").Delete <-----highlighted error line Application.DisplayAlerts = True DataBook.Worksheets("Database").Move before:=Tool.Worksheets(1) The VBA script is attempting to take raw data from an Excel sheet that I have already generated, and import the file (thus that part in the Set line) and perform a number of calculations to create more data and stats from there. However the problem I feel lies in the section I posted here and the objects and variables. The highlighted error row is the one that says Tool.Worksheets("Database").Delete. When I added a Watch to that row the value states Object Variable or With block variable not set. This leads me to believe something is not being set as it should as an object, but again I am a VBA newbie and I am not confident about any of my gut feelings. For what its worth, I should mention I added another Watch to the line that says DataBook.Worksheets("Sheet1").Name = "Database" and the value for that states Subscript out of