Runtime Error When Closing The Sheet
Apr 20, 2006
This is a simple macro to hide the sheets if macro is disabled. But I get an error when I close the worksheet. Can anyone please help me with this. Other than that, everything seems fine. The problem is only when closing the worksheet if get an error as " run-time error '1004': Method ;visible' of object' _worksheet' failed". The code is given below.
Public bIsClosing As Boolean
Dim wsSheet As Worksheet
Sub HideAll()
Application. ScreenUpdating = False
For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.CodeName = "TABLE" Then
wsSheet.Visible = xlSheetVisible
Else
wsSheet.Visible = xlSheetVeryHidden
End If
Next wsSheet
Application.ScreenUpdating = True
End Sub
Sub ShowAll()
bIsClosing = False
For Each wsSheet In ThisWorkbook.Worksheets
If wsSheet.CodeName <> "TABLE" Then
wsSheet.Visible = xlSheetVisible
End If
Next wsSheet
End Sub
View 9 Replies
ADVERTISEMENT
Apr 13, 2008
Why do I get the error: "Runtime error 1004: Cannot rename a sheet to the same name as another sheet, a reference object library, or a workbook referenced by Visual Basic"?
And how do I fix it? I have a macros that someone else made (thank you) and I need to make the macros create anywhere from 5-125 sheets based on the information added in sheet 1. How can I do this whe it stops me after 5 or so with the error above.
View 10 Replies
View Related
Apr 17, 2014
I'm generating a runtime 1004 error with the macro I have attached to CommandButton1, "Clock_In".
The macro is copying the name, date and time from 3 cells on Sheet1 and pasting special values to another sheet.
View 2 Replies
View Related
Feb 14, 2014
I have a very basic code to copy "non-blank" data from one sheet and paste to another. The code is not complete yet - I am running in debug mode I get the above error. My code is as below.
Sub SampleFind()
Dim StrWord As String
Dim Quantity As String
Dim i As Long
Call nrows
For j = 2 To 2
For i = 2 To nrows1
[Code] ..........
View 4 Replies
View Related
May 9, 2006
I am currently working on a project which at various times does 2 different things. These things are to be done on a "PROTECTED" (UserInterfaceOnly:=True ) worksheet.
The first is a Range.Replace command.
The other is a Hyperlinks.Add command.
Now when I'm testing ( typically the worksheet is not protected ) everything works like a champ. But as soon as I protect the sheet the following scenario happens.
1. The replace DOES NOT work.
2. The hypelink.add DOES NOT work.
when the sheet is protected it ends up throwing a runtime error ( 1004 ) "Protected Sheet error" the real odd thing about this is that it doesn't throw the error on the command itself. On the hyperlink the error happens about 3 command further along in the flow............
View 5 Replies
View Related
May 3, 2012
This first macro works fine:
Sub UnhideHBPorCholesterolQ1toQ3()
'
ActiveSheet.Unprotect "password"
Rows("58:67").Select
[Code]....
why the second macro does not seem to work. I get a Run-time error that says "Unable to set the Hidden property of the Range Class".
View 1 Replies
View Related
May 20, 2013
The code below works nicely to insert a time stamp in column B when the user selects "Yes" in the corresponding cell in column A. The problem is if I try to delete any rows or clear the contents of the cells I receive a "Run-time Error 13 - Type mismatch." If I delete the contents of the cells one at a time I do not receive the error. What I am trying to do is the user has a list of items to select from in column A. Only if "Yes" is selected I want the time stamp in column B to appear.
Code is below.
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Value "Yes" Then Exit Sub
If Not Intersect(Range("A1:A50"), .Cells) Is Nothing Then
Application.EnableEvents = False
With .Offset(0, 1)
[Code] ......
View 6 Replies
View Related
May 3, 2006
I'm getting the error for the following piece of code.
Sub itconfandscratch()
Dim Cn As ADODB.Connection
Dim Server_Name As String
Dim Database_Name As String
Dim User_ID As String
Dim Password As String
Dim SQLStr As String
Dim rs As ADODB.Recordset
Set rs = New ADODB.Recordset
Server_Name = "sturecord"
Database_Name = "Scratch" ' Enter your database name here
SQLStr = "SELECT stuname FROM dbo.sturec" ' Enter your SQL here
Set Cn = New ADODB.Connection
Cn.Open "Driver={SQL Server};Server=" & Server_Name & ";Database=" & Database_Name & ""..............
View 2 Replies
View Related
Nov 3, 2006
I have an error that just began occuring as I am developing a VBA application in Excel.
Whenever I close the workbook, an Error 91 occurs. The VBA editor opens and a line is highlighted within my combo box change event. It is stating that the combo box item no longer exists.
The combo box actually resides as an embedded control with a sheet.
View 9 Replies
View Related
Jul 6, 2006
I do not understand why my code returns a Run Time Error"9" Subscript out of range. With the following code, I opened a workbook and then wish to close that same workbook without saving. Eventually I will be pulling information from the workbook but for now I just want it to open and then close right away.
Private Sub cb_NewDate_Change()
ListIndex = cb_NewDate.ListIndex
If ListIndex = 0 Then
Application. ScreenUpdating = False
Workbooks.Open Filename:="I:JoeNetwork Conversion FactorsNetworkConversionFactors_Ver_2_0_0.xls"
Application.Workbooks("I:JoeNetwork Conversion FactorsNetworkConversionFactors_Ver_2_0_0.xls").Close False
End Sub
View 3 Replies
View Related
Jul 6, 2006
The code thats generating the error is the following:
For Y = 8 To 131
TmpDate = Empty
Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
TmpDate = Range("A1").Value
For Langd = 1 To Len(TmpDate)
TmpChar = Mid(TmpDate, Langd, 1)
If Not TmpChar = " " Then
TmpComp = TmpComp + TmpChar
End If
Next Langd
TmpDate = TmpComp
TmpComp = Empty
If Len(Dag) = 1 Then
Dag = "0" + CStr(Dag)
End If
Macro continues before the Next-statement...
(it might not be good programming, but I think it should work).
A little explanation to the code.
I have a spreadsheet located on the intranet that has values I need in my spreadsheet. These figures are sorted by date, so I search for the date to find the right figures.
The line Range("A1").Value = "=" + Path + Sheet + "B" + CStr(Y)
works prefectly. I can see the value in my spreadsheet in the cell A1. its the next line that causes the error "Type mismatch".
The value I get from the intranet spreadsheet looks similar to this:
"1 Jul 2006 " (note all the spaces).
What I do is just run it through a loop and cut of all spaces so it will look like this: "1Jul2006" to be sure I dont miss a space or anything.
Now to the funny part.
The error only happens at runtime on the first go.
If I chose to END the macro then and there, and then run it again from the top it works perfectly.
If I set a stopsign to debug the code, it works perfectly on the first go too.
Can anyone explain to me why that happens??
I know enough about programming to handle my syntax errors and so on, but I cant see anything wrong in this one...
Please note that this isnt the the entire code.
I'm building a report on 12 diffrent spreadsheet. The main macro is almost 2000 rows of code, and it call other Subs too (because of limitations in the VBA-editor. A macro cant to be too big), so its impossible for me to post the entire macro...
View 9 Replies
View Related
Feb 6, 2014
The following code opens a window where you can search for "*.dat" files. The coded works fine but if for instance I would like to cancel the file opening (clicking at the cross or cancel button), and error will pop up saying "mysmsaf".
Is there a code which I can introduce so that I can cancel or close the open window without error?
[Code] .....
View 3 Replies
View Related
Nov 2, 2007
My indirect formula doesn't work when I have the entire path defined. I have the entire filepath specified (which will never change), and then I have cell A6 with the tab name of the worksheet on the workbook
.
Workbook 1 named 'Testme' contains the table with range a2:b5
Worbook 2 contains the formula
I put this formula into workbook2 (the tab in the example is named hitab & I put that name in cell B6)
Here is what I have:Does not work even when other workbook is open
=VLOOKUP(B6,INDIRECT("'H:CUSTOMERSCurrentClientAMRO and General SuppliesBearings, Motors, PTsSavings Tracking[Testme.xls]"&A6&"'!a2:b5"),2,FALSE)
This DOES work when workbook is open, but not when it is closed (which would seem logical if when the workbook is closed, the formula needs the exact path)
=VLOOKUP(B5,INDIRECT("[Testme.xls]"&A6&"!$a$2:$b$5"),2,FALSE)
I can hard code everything except the tab name. Why doesn't Indirect recognize an entire file path and also why does it give a REF error?
- I did a search and found that some people said to use the add-in Indirect.exe. I followed the link and the page was no longer found.
View 9 Replies
View Related
Mar 5, 2007
if I leave the inputbox blank I get an Excel error. I.e. it says that the formula I tried to type contains an error..... Is the Type:=8 not working properly here?
Dim Addr As Range
On Error GoTo Problem
Set Addr = Application.InputBox( _
Prompt:="Enter or Select a cell in the last record", _
Title:="Select Last Record:", Default:=Selection.Address, Type:=8)
If Addr Is Nothing Then Exit Sub
Edit: I guess I should mention that I am trying to retrieve a cell reference from the user via an input box. This cell reference will help me determine the last record in the spreadsheet.
View 9 Replies
View Related
Sep 18, 2007
In Excel 2003 I have made a model for evaluating co-workers. The model consist of a number of different questions regarding performance. At the top of the sheet, the user have to select som data from a drop down list, and depending on the answer (upward or downward), som of the questions in the sheets is hidden or shown. For this purpose I have created this string of VB-code in the sheet:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$5" And Target.Value = "Upward" Then
Rows("20:41").EntireRow.Hidden = True
ElseIf Target.Address = "$E$5" And Target.Value = "Downward" Then
Rows("20:41").EntireRow.Hidden = False
ElseIf Target.Address = "$E$5" And Target.Value = "" Then
Rows("20:41").EntireRow.Hidden = False
End If...........
View 3 Replies
View Related
Oct 30, 2008
He's the issue i'm getting with the code...
Public Sub Auto_Open()
wrkbkName = Application.ActiveWorkbook.Name
'this little snippet of code determine which branch the user is at
'based on the ip address
'if ip is like 192.168.1.xxx then we on welthsrvr
ipadrr = GetIPAddresses(True)
If Left(ipadrr, 9) = "192.168.1" Then
View 9 Replies
View Related
Dec 14, 2008
Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Application.Intersect(Target, Range("G9:BF94")) Is Nothing) Then
With Target
If Not .HasFormula Then
.Value = UCase(.Value)
End If
End With
End If
End Sub
However when ever I select more than one cell which already has text in it and press delete I get a runtime error 13 and the debugger highlights this line:
.Value = UCase(.Value)
View 9 Replies
View Related
Jan 26, 2009
I get a runtime error 9 on my excel form.
This line is highlighted:
Workbooks("Proposal for XL.xlsm").ActiveSheet.Range("S13:AH13").Copy
View 9 Replies
View Related
Apr 12, 2006
I have created a workbook for external users that allows them to track data on a monthly basis and submit to me. Each spreadsheet has a code to sort names alphabetically. Here is the
Sub Button53_Click()
Dim i
For Each i In [B10:K309]
If i.Value = 0 Then
i.Value = ""
End If
Next
ActiveSheet. Unprotect Password:="xxx"
Range("B10:AB309").Select
Selection.Sort Key1:=Range("B10"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
ActiveWindow.ScrollRow = 10
ActiveWindow.SmallScroll ToRight:=-5
Range("B10").Select
ActiveSheet.Protect Password:="xxx", DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Everything works great for the majority of users, but those who are using Excel 97 return a runtime error on the following line: If i.Value = 0 Then. This code was created in Excel 2000 since that was the software our office used.
View 5 Replies
View Related
Apr 5, 2007
I'm getting Runtime Error 91 on this line:
destRange = Range(.Cells(destRow, 2), .Cells(destRow, 7))
Here is the overall function:
Public Sub sendRow(myRow As Integer, destinationSector As Integer)
'************************************************************
'1. Copy Row... Cols 2-7
'2. Find First Empty in new Sector
'3. Paste Row on first new Row
Dim myBounds() As Integer
Dim destRow As Integer
Dim destRange As Range
Dim cutRange As Range
Dim y As Worksheet
myBounds = getSecBounds(destinationSector)
This subroutine is being called from the Worksheet_Change event, and should therefore have an active sheet.
View 5 Replies
View Related
Jul 24, 2007
I am trying to copy the info from one workbook to another workbook.
I keep getting the above referenced error...
Private Sub CommandButton1_Click()
Dim filepath As String
filepath = Range("A100")
MsgBox ("File Appended")
Workbooks.Open (filepath)
Windows("CorrespondenceMaster.xls").Activate
Sheets("Sheet2").Select
Range("DesNo", "LocationPath").Select
Selection.Copy
Windows(filepath).Activate
Range("A2").Select
ActiveSheet.Paste
End Sub
View 3 Replies
View Related
Jan 12, 2007
Is there a limit on the amout of pictures you can use with the statement me.pictures.visible? Reason being, I am trying to import 119 pictures into a spreadsheet. When the information is selected form a drop down list, it pulls up the 1 of the 119 pictures. I was able to get 54 pictures input. Everything was going great until the 55th. When it stared giving me an error...
______________________________________________
Runtime Error '1004':
Unable to set the Visible property of the Pictures class
______________________________________________
When I select Debug, it takes me to the line with Me.Pictures.Visible = False
Everything seems to work fine until I enter the 55th picture. If it is that, is there a viable work around?
View 9 Replies
View Related
Feb 22, 2007
Getting a error message when opening a workbook "Runtime error 1004" I dont know much about excel and the user explained it to me as best she could . Here is where the script bugs:
Sub auto_open()
fdist = ActiveWorkbook.Name
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Worksheets("f_cumul").Cells.ClearContents
Worksheets("f_cumul").Cells.ClearFormats
Worksheets("vtes_dj").Select
Range("a1").Select
Selection.End(xlDown).Select..............
View 9 Replies
View Related
Oct 19, 2007
I have read the other posts on here and swapped, Dim timeinc As Interger to Dim timeinc As Long and Dim timeinc As Double but neither worked. They both make the calculation 0 and I can not figure out why. This macro has worked before and is failing only on this new dataset which I have attached as well.
I am solving this problem on a PC and the macro was built for a Mac but I do not think that should change much as when I run it on a Mac it fails the same
View 11 Replies
View Related
Nov 3, 2008
I've been having some problems with my company's spreadsheet in terms of calculations using Add Ins.
Some of the functions work within the spreadsheets - others give me a runtime '9' error,
View 14 Replies
View Related
Oct 20, 2011
I have an application using two userforms. Following sequence is used:
1. Open Userform1 (with uf.show)
2. click on a commandbutton in userform1 opens a second userform on top of userform1.
3. Close userform2 with commandbutton on userform2 (userform2.hide)
(I did not want the user to close the UF via the "X" )
Runtime error 402 : Must close or hide topmost modal form first
So, I changed my code so when the user clicks the commandbutton in userform2
userform1.hide (which is the topmost)
userform2.hide
But again I get the same error.
View 7 Replies
View Related
Sep 14, 2012
I have a script that usually runs, but all of a sudden gives me a run-time error 6: Overflow error. Basically I'm searching for certain criteria and copying or cutting and pasting lines from one sheet to another. Why I'm getting the error by the code below?
Sub teal()
Dim i As Long
Dim qq As Long
Dim assignmentnum As Long[code]......
View 9 Replies
View Related
Apr 21, 2014
When I run the following code it keeps giving me a runtime error 1004.
Code:
Sub ImportData()
Dim fNameAndPath As Variant
Dim wb As Workbook
Dim cNextRow As Long
Dim Ans As String
NextRow = ThisWorkbook.Worksheets("Errors").Range("B" & Rows.Count).End(xlUp).Row + 1
cNextRow = ThisWorkbook.Worksheets("Compare").Range("A" & Rows.Count).End(xlUp).Row + 1
[code]...
View 3 Replies
View Related
Jul 16, 2014
I have a bug on a macro that was working until yesterday. I did not write this macro and I cannot seem to fix it. The debug stops at the below command. The data it looks at seems to be in the right format so I think there is something else that is wrong.
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=PRange)
View 3 Replies
View Related
Feb 15, 2008
I have this macro and I keep getting a 1004 runtime error 'PasteSpecial method of range class failed' on the highlighted line,
Sub Print_()
'
Sheets("Sheet1").Select
Cells.Select
Selection.Copy
Sheets("Print").Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
With Selection.Interior
.ColorIndex = 2
.PatternColorIndex = xlAutomatic
End With
View 9 Replies
View Related