Private Sub Worksheet Error
Feb 24, 2009im getting run time error 40036 and i dont know how to correct it here is the code
View 9 Repliesim getting run time error 40036 and i dont know how to correct it here is the code
View 9 RepliesI have a Private button sub in Sheet2. I use it to call a sub in Module1. Like this:
Private Sub button_Click()
Call MacroModule
End Sub
It works when the sub in the module ("MacroModule") is declared as a normal sub.
But I want to declare it as a Private sub so it does not show up on the macro list.
When I change the Macromodule to a private sub, the call gives an error saying sub is undefined.
I have the following code which performs a different action depending on whether K1 says "true" or "false". K1 contains a formula which identifies whether or not E1 is already present on a list on another page. If K1 says "false," the code is supposed just reenter the formula that was previously in E1 (because I don't know how to tell it to do nothing). If K1 says "true," I want a popup box where answering yes reenters the previous formula and answering no pulls up an input box to enter other data. This code worked fine until I closed the workbook. When I tried to open it again, I got a runtime error 9: subscript out of range message and nothing happens when I change the value in A1 (upon which the formula in E1 is based).
Private Sub Worksheet_Calculate()
Application.EnableEvents = False
If Sheets("Mix Designs Input").Range("K1").Value = "true" Then
Range("E1").Select
Ans = MsgBox("Do you want to overwrite this mix design?", vbYesNo)
If Ans = vbNo Then Title = InputBox("Enter the name of the design you wish to input")
Range("E1") = Title
If Ans = vbYes Then ActiveCell.FormulaR1C1 = _
"=IF(ISBLANK(RC[-4]),"""",IF(ISERROR(VLOOKUP(""reclaim"",R[8]C[-4]:R[13]C[-
I have a worksheet with a bunch of formulas in it. Computations are done on the worksheet and then I start a macro that copies the sheet and replaces the calculations with values.
The worksheet has a sheet level private sub.
All my macros in Module 1 work OK when I password protect my Excel 2003 worksheet named: Data. The only code that does not work when I password protect my worksheet is the Private Sub shown below. If I do not use a password, it works OK. As soon as I enter a password to protect my worksheet, the code below no longer works.
In ThisWorkbook, the following code shows the password to be password. In reality, there is a different password.
IN SAME SHEET.
1. IS TO RESTRICT CELL POINTER. EG. HIT {ENTER} : COL(1) TO COL(5)
2. IS TO RUN PROCEDURE WHEN DATA IS INPUTTED IN COL(3)
THESE TWO SUB CAN RUN IN ONE SHEET ?
Private Sub Worksheet_Change(ByVal Target As Range) 'SHEET1
ActiveCell.Offset(0, 0).Activate
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean) 'WORKBOOK
Application.OnKey "{ENTER}"
Application.OnKey "~"
End Sub
VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Target.RowHeight = 16
End Sub
[Code]....
How to Use 2 Private Sub Worksheet_Change
I have a drop down box selecting from a list of dates (Oct-13 - Dec-14) that I need to display as "mmm-yy" to the end user so have written the following code to format when a date is selected:
Code:
Private Sub SDatePicker_Change()
SDatePicker.Value = Format(SDatePicker.Value, "mmm-yy")
End Sub
For some reason the code seems to run through itself twice and I can't figure out why. The result of this is an incorrect date being displayed (strangely when I select 'Jan-14' for example, the result is 'Jan-13'.
Perhaps I should point out that the default formatting of the date values seems to be in number format e.g. 41976.
I have VBA script to format a csv.
As part of the formatting, i want to add a private sub to the activesheet that will enable a colour-on-click function.
How can I make the overall VBA script insert of the privatesub into Sheet1?
I have two funtions which I am trying to put in ThisWorkbook.
Private Sub Workbook_Open and Private Sub 2. The Workbook_Open calls on Sub 2.
Now, with both of these in ThisWorkbook, I get the error that Sub 2 macro cannot be found.
And if I put the Sub 2 in a module, everything works.
Now, I am trying to put both in ThisWorkbook instead of only one.
I currently have this code in my sheet, and would like to incorporate the second bit of code into the same sheet, but not sure how to do it. At this point, when I just put them together neither will work.
Option Compare Text
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column 12 Then Exit Sub
If Target.Value = "Daniel Amaya" Then
Target.EntireRow.Cut
Sheets("Daniel").Range("A3").End(xlUp).Offset(1, 0).EntireRow.Insert
Target.EntireRow.Delete
My Workbook contains 12 worksheets and in each Worksheet there is a drop down list. The code for each one is in the worksheet code section where they are Private Subs.
What i want is that once the work book opens it will run the code in each of the work sheets instead of going into each bit of code and running it manually.
the below macro works when the worksheet name is Sheet1, but as soon as i change the worksheet to Rec it does not work, what have i done wrong?
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Not Sh Is Sheet1 Then
If Sheet1.AutoFilterMode Then
If Sheet1.FilterMode Then Sheet1.ShowAllData
End If
End If
End Sub
Does not work
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Not Sh Is Rec Then
If Rec.AutoFilterMode Then
If Rec.FilterMode Then Rec.ShowAllData
End If
End If
End Sub
My nacro wont work if I put private infront of sub, if I take out private it works. Its not connected to any object, just simple copy paste
View 9 Replies View RelatedI have 3 different sheets with a private sub on each all labelled
Private Sub CommandButton1_Click()
The macro's runs fine on each page.
I want to put a macro on a separate sheet that i can run each of those macro's
I did initially copy the original private macro and change the
Private Sub CommandButton1_Click()
to
sub report()
But I couldn't do all 3 in the same manner. i did change each name to something different... the other 2 subs did run, but they didn't do anything except put the massage box on the end saying that "the macro has finished".
The private macros are on sheets 26, 28 and 12.
Is it possible to call a Private Sub from another Module?
View 2 Replies View RelatedThe code below writes the names of all active worksheets into the A column of the active worksheet. I have a situation where I have 2 workbooks open (3 if you count PERSONAL.XLS). One of the worksheets has a consistent name, the other has a name that changes every week (not in a consistent pattern).
I'd like to be able to use the routine below to get a list of open workbooks, ignore the one I'm working in and PERSONAL.XLS, and instead put the remaining filename into other Private Subs in a User Form to run other routines.
Here is my simple Private Sub that I can't get to work,
Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
For Each c In Target
[Code]....
I have a checkbox control that changes the value to "True" or "False" in column 4. Here lies the issue, if I use the check box control to change the value, the private sub does not work. If i type the value of "True" or "False" where the check box control stores its value, the private sub works. I would like to see if there is way to get the private sub to work by simply clicking on the check box control only.
Private Sub to do the following:
'Add Formula to column "G" of any active row.
Range. Rows 8 thru 9999
If any value is input into column "C" and/or column "F" of the active row
Then Insert and activate Formula "=c*f" into column "G" of that row.
I usually create fairly simple macros using 'button' feature. However, now I'm using the 'CommandButton', as I had to make buttons highlighted once selected - So I have a choice of five options, whichever the user chooses that option background changes, the others stay grey...anyway, thats the fancy-editing done, but now when i enter a simple instruction - hide rows function - I get the error message "Select method of range class failed"
Here is the full code - like i say it works fine when its just the editing, but when i try to actually hide rows it doesn't work. - I will also add that the code is inside 'Microsoft Excel Objects' and further 'Sheet 1 (INDEX)' - not a module - I'm not sure if this is important.
Private Sub JackStart_click()
JackStart.BackColor = 32896
JackStart.ForeColor = 16777215
JackStart.Font.Bold = True
Majix.BackColor = 8421504
Majix.ForeColor = 0
Majix.Font.Bold = False
Sheets("Bank Reconciliation").Select
Rows("3:3").Select
Selection.EntireRow.Hidden = True
Sheets("INDEX").Select
Range("A1").Select
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$b$1" Then
For i = 1 To 10
Cells(1, 1) = i
Next i
End If
End Sub
It is supposed to count to 10 when the info in cell B1 changes, i would like to use it as a timer.
I need a line of code so that when I hit commandbutton2, the Private Sub Worksheet_Change(ByVal Target As Range) event macro on the same page DOESN'T run. The button clears certain lines, and when it runs the change event it ends up in an error, and I don't need it to run when hitting the commandbutton.
View 6 Replies View RelatedI have some code in which I need to pass the value of "j" from one module to another. "j" is declared in Sheet1 (Data) under the Microsoft Excel Objects.
View 8 Replies View RelatedI am trying to pass a variable called "Filter" from a Private Sub to a Module but keeping coming up with a zero value in the Module. I tried to make the variable Global but that didn't seem to work.
Private Sub Code as follows:
I am trying to declare lngLr as Long and Constant. But it's buggin out on me. Is this the correct way to do it?
Code:
Private Const lngLr As Long = ".Cells(Rows.Count, 1).End(xlUp).Row"
Sub calculate_active_employees_sheet_years_of_service_w_Oasis()
Application.ScreenUpdating = True
[Code].....
I want this private sub macro to change work in all workbook. How it possible?
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Cells.Interior.ColorIndex = xlNone
With Target.EntireRow.Interior
.ColorIndex = 37
.Pattern = xlGray25
.PatternColorIndex = 24
End With
End Sub
I want Excel to play a specific sound when a "-" is entered in any cell. How would I go about doing this?
View 3 Replies View RelatedHow do disable Private Sub Macro
I have a private sub macro for Sheet1 as shown below
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address "$B$2$" Then Sheets("Start").Select
Exit Sub
End Sub
And I have another macro (call ADDNumLine) that add additional data to the Sheet1. How do I temporally disable the Private Sub above when executing Macro AddNumLine?
why the code below might not execute ? It just seems like it skips over the code and doesn't run at all.
Private Sub Workbook_Open()
'AssignRequestNumber()
MsgBox ("Whoa")
Run "AssignTrackNumber"
End Sub
I have a macro assigning a unique number to the file in a fixed cell whenever the .xlt file is opened from File-New.
I would like the users to be able to exit the whole module via double clicking the form. When the form is double clicked, the double click event appears and I am wondering how to put code into this procedure which exits the whole module.
View 3 Replies View Related