I wrote the following line of code to find the last row in Column C in my workbook:
lastRow1 = Workbooks("ExcelBook").Worksheets("Prices").Range("C65536").End(xlUp).Row
When I run my macro on my own computer (Excel 2010, Windows 8) it works fine. However, I sent it to a client of mine (Excel 2007, Windows 7) and he gets a "runtime error 9 - subscript out of range"
The same thing also happens if I run the macro on Excel for Mac... Could someone help with this?
Thanks!
I've run into a similar issue, macros not working on certain computers - it could need the full workbook name with the extension. Try
lastRow1 = Workbooks("ExcelBook.xlsx").Worksheets("Prices").Range("C65536").End(xlUp).Row
I had a very similar issue with
dstring = Workbooks("name").Worksheets("name2").Range("name3")
and the issue was solved by adding the extension
dstring = Workbooks("name.xlsm").Worksheets("name2").Range("name3")
Related
I have a VBA macro in excel that used to work fine for a few days but today when I launch it's not working anymore. Funny thing is that no changes were made to the excel file nor the macro.
The macro is attached to a button and gets data from a TextBox named CSVExportRange. When I try to launch it I get an
"Object doesn't support this property or method"
error in the line where I set Range based on value of the textfield:
Dim r As Range
Set r = Range(Application.ActiveSheet.CSVExportRange.Value)
I tried experimenting with it and it turns out it doesn't see the TextBox at all now:
Dim a As Worksheet
Dim k As TextBox
Set a = Application.ActiveSheet
Set k = Application.ActiveSheet.CSVExportRange
In the above case debug breaks at the last line with "Object doesn't support this property or method" error.
I have the TextBox setup properly and didn't change it since last time everything worked fine.
What's wrong?
No idea why it happened but restarting Excel twice helped...
Like, when I closed all Excel files and relaunched it, it was not working still. After doing so once more it started working again.
Note that neither is a remote / network / shared file so it's not a case of someone / something else locking some file...
I have an Excel Macro Enabled workbook that I created on Excel 2013. The workbook's macros work well with my computer but does not work on some other computers even if they are using Excel 2013. Works on 7/10 computers I tried both on windows 7 and 8. When I send it to someone's computer that does not work this is what happens:
They open the workbook and once the user clicks "enable content" the workbook errors out "run time error '32809': Application-defined or object-defined error"
debug shows it getting stuck on 2nd line of code below:
private sub workbook open()
Worksheets(1).OLEObjects("ComboBox21").ListFillRange = "impacts"
**Worksheets(2).OLEObjects("ComboBox21").ListFillRange = "yesnoo"** This line errors
if I comment out these two lines, the workbook will open but the combobox21 on worksheet(2) gets renamed to combobox22 and does not work but the first combobox on worksheet(1) loads and functions fine.
I would like to add that if I comment out the lines
Worksheets(1).OLEObjects("ComboBox21").ListFillRange = "impacts"
Worksheets(2).OLEObjects("ComboBox21").ListFillRange = "yesnoo"
I get the error now that "Can't exit design mode because control ' dattimepicker21' cannot be created
I found and fixed the problem, the machines that were not working were missing MSCOMCT2.OCX
http://answers.microsoft.com/en-us/office/forum/office_2013_release-excel/date-picker-dropdown-in-excel-2013/71decdcd-6cc6-4a70-b1ab-20294a2a315a
All,
I just upgraded to Excel 2013 and am running into a strange issue. I have a macro-enabled workbook that has worked successfully for quite some time now. I was updating some of the code and came across this error (32809) when trying to write to a specific sheet. In troubleshooting, I tried this.
Sheets("Summary").Range("G8").Value = "Test"
This resulted in the same error. Then I tried this.
Debug.Print ActiveSheet.Name
Same error. So I selected another sheet on the workbook and debug.print on the name. Worked fine.
Then I tried this.
Debug.Print Sheets(2).Name (This is the sheet number of the problemic sheet)
Same error. It seems to me that there is some form of corruption with this sheet but I am reticent about deleting and recreating. Any suggestions?
Thanks!
While it wasn't a perfect solution, here is how I finally resolved it. I had a user that was still on Excel 2010 make a copy the corrupt sheet within the same workbook, delete the corrupt sheet, then rename the new sheet to the original name. I was then able to use the workbook in Excel 2013 without issue.
I have a Workbook Open Macro which counts the number of rows in a table on opening so that I can summarize how many records were added or deleted during the data entry session:
Private Sub Workbook_Open()
Dim TotalRows As Integer
TotalRows = Worksheets("Data").ListObjects(1).ListRows.Count
If Range("LastRecordOnStart") <> TotalRows Then Range("LastRecordOnStart") = TotalRows
' Stop
End Sub
I started getting the run-time error '32809' with the following line in the code above highlighted in the debugger every time I opened the workbook...
TotalRows = Worksheets("Data").ListObjects(1).ListRows.Count
Rebooting or opening the workbook on another PC still would not fix it. Even opening a previously saved working copy would give the same error - strange. Note:
While coding, I will periodically save the workbook and use windows explorer to copy a snapshot of the workbook where it creates myworkbook copy(1).xlsm, copy(2).xlsm, etc and if I get a corrupted workbook, I rename it myworkbook.bad.xlsm and rename the latest saved working version (e.g myworkbook copy(6).xlsm to MyWorkbook.xlsm with minimal loss.
When this run-time error occurs though, I've had to rebuild the book several times. It only appears to happen when the workbook crashes after a long session of debugging new code with the Userform open and I have to close excel from the Task Manager.
I read the posts here today and was convinced that it was page related when I could list the listrows count on another sheet and if I converted the Listobject on the "Data" worksheet back to a range and recreated the table, I'd still get the run-time error. To cut a long story short, I tried the following:
Open the workbook
When the error popped up, clicked debug
Right clicked on the "End Sub" line of the WorkBook_Open sub and clicked "Set Next statement"
Pressed F5 to allow the code to finish executing
Saved the workbook and it all works now!
I had another crash with the subsequent run-time error and repeated the steps above and it worked a charm again.
I want to delete the VBA code contained within a sheet through VBA. Currently, I have a code that copies a sheet across to a new workbook and deletes all images from it. However, these images are set to do things on Worksheet_Activate in the code, which then causes an error whenever I flick to that sheet with no images there.
I know I can get rid of modules etc using something along the lines of:
With ActiveWorkbook.VBProject
For x = .VBComponents.Count To 1 Step -1
.VBComponents.Remove .VBComponents(x)
Next x
For x = .VBComponents.Count To 1 Step -1
.VBComponents(x).CodeModule.DeleteLines _
1, .VBComponents(x).CodeModule.CountOfLines
Next x
End With
but that does not delete from the sheet (or the workbook for that matter. Would be interesting to know if that was possible too).
The code itself will need to be valid for Excel versions 2003 through to 2013 (so cannot use the save as xlsx workaround).
Found out the issue. My code works fine, just the computer I was testing it on did not allow access to the VBA project object model (and was running it with an On Error Resume Next earlier on in the code)
Will have to write an exception in to sort that out in such cases.
Thanks to #mehow #nixda #SiddharthRout and #DaveU for the help
All,
I've recently built a worksheet mostly run by VBA macros (built in Excel 2007). One of the functions of this sheet is that when a user clicks a button, it runs a macro which populates a listbox in a form, then shows the form and allows them to do a couple things related to that list.
This macro works fine on my computer and also for 3 or 4 other users' computers that I've tested it on in my office.
However, when a user located in Poland tries to use it, he receives a 'Could not set the list property. Type Mismatch' error when he clicks the button.
He's using Office 2010 Plus. I've tested this on a coworkers computer in my office who's also using 2010 and it worked fine.
The user getting the error does appear to be using a Polish version of excel, so I'm not sure if this is contributing to the problem? The following is the code that's returning the error:
Sub AccountAssignmentChange()
count = 0
AssignAccounts.ExecName.Caption = "Account Management for " _
& ActiveSheet.Range("D4").Value
For i = 2 To 9
If Not Sheet1.Cells(i, 33) = "" Then
With AssignAccounts.RegionBox
.AddItem
.List(count) = Sheet1.Cells(i, 33)
count = count + 1
End With
End If
Next
AssignAccounts.Show
End Sub
For clarification, Activesheet.Range("D4").value is an employee name. Sheet1.Cells(i,33) (for 2 to 9) is a range containing region names that get populated into the list box.
The employee getting the error has access to one region (this means the list box should be populated with one item). I've changed my access to only that region and had no problems. Also did so for the user using 2010 in my office and it worked fine for him.
Also, here is a screenshot of the error the employee sent me.
Any ideas? Pretty lost with this error.
EDIT: I now have an (I'm assuming) unrelated development. This particular employee is now receiving an error stating "Microsoft Excel is waiting for another application to complete an OLE action".
I'm also stumped on why this error is getting thrown. For info: There's a macro that runs on workbook open that opens another worksheet that sits on a shared drive. The shared drive is already mapped to this employee's computer, so that's not an issue.
The workbook being accessed remotely is a shared workbook because multiple people may be using this worksheet at the same time.
This employee is receiving the OLE error when the macro tries to open the workbook. When he hits 'OK' the notification stays there and effectively hangs.
I have no idea why this is happening. I thought there might be a problem with two people trying to access the shared workbook at the same time, but I tested this with a couple coworkers located in my office, and it worked without issue.
Any ideas on this? This particular employee is having issues that totally stump me.
Use the below (edited) code. You need to keep in mind that ListBoxes are like grids, the .List property takes a Column and Row parameter... i.e. .List(1, 0)... ALSO - make sure that the user in Poland has the reference (Microsoft Office 14.0 Object Library) added to his workbook...
Sub AccountAssignmentChange()
count = 0
AssignAccounts.ExecName.Caption = "Account Management for " _
& ActiveSheet.Range("D4").Value
For i = 2 To 9
If Not Sheet1.Cells(i, 33) = "" Then
With AssignAccounts.RegionBox
.AddItem 0 'Speficy the list reference (top)
.List(count, 0) = Sheet1.Cells(i, 33) 'Call the correct list...
count = count + 1
End With
End If
Next
AssignAccounts.Show
End Sub