Simple Private Sub Not Working?

May 7, 2012

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.

View 9 Replies


ADVERTISEMENT

Simple Code In 'Private Sub'

Jan 8, 2008

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

View 9 Replies View Related

Simple Color Code Not Working On Specific Sheet

Jul 22, 2013

This very simple color code below worked before but now it gives "Application-defined or object-defined error". When I try it on a new workbook, it works fine.

Code:
Sub sdsdfsd()
Selection.Interior.Color = 65535
End Sub

View 1 Replies View Related

Two Private Sub

Apr 29, 2007

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

View 5 Replies View Related

How To Use 2 Private Sub Worksheet_Change

Jul 10, 2013

VB:
Private Sub Worksheet_Change(ByVal Target As Range)
Target.RowHeight = 16
End Sub

[Code]....

How to Use 2 Private Sub Worksheet_Change

View 6 Replies View Related

Private Sub Running Twice

Oct 22, 2013

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.

View 3 Replies View Related

VBA To Add Private Sub To Sheet?

Jun 15, 2014

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?

View 2 Replies View Related

Difference Between Private Sub And Sub

May 30, 2007

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.

View 9 Replies View Related

Two Private Sub Worksheet_Change

May 22, 2008

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

View 9 Replies View Related

Getting A Private Sub To Automatically Run

Sep 2, 2008

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.

View 9 Replies View Related

Private Sub Worksheet_Activate

Oct 8, 2008

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

View 9 Replies View Related

Pt Private Infront Of Sub

Jan 13, 2009

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 Related

Running Private Sub From A Macro

Mar 17, 2014

I 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.

View 3 Replies View Related

Private Sub Worksheet Error

Feb 24, 2009

im getting run time error 40036 and i dont know how to correct it here is the code

View 9 Replies View Related

Call A Private Sub From Another Module

Aug 13, 2009

Is it possible to call a Private Sub from another Module?

View 2 Replies View Related

Place File Name Into Private Sub

Dec 11, 2009

The 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.

View 6 Replies View Related

Private Sub To Insert Formula

Sep 7, 2013

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.

View 9 Replies View Related

Private Sub Worksheet_Change (timer)

May 13, 2008

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.

View 9 Replies View Related

Delete Worksheet Private Sub After Paste

Mar 20, 2014

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.

View 6 Replies View Related

Prevent Private Sub Macro From Running

Nov 14, 2008

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 Related

Passing A Private Variable To Another Module

Nov 25, 2008

I 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 Related

Passing Variable Value From Private Sub To Module

Aug 12, 2009

I 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:

View 3 Replies View Related

Private Sub And Worksheet Protection With Password

Jan 24, 2010

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.

View 10 Replies View Related

Declare Private Constant As Long?

Dec 27, 2012

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].....

View 4 Replies View Related

Change Private Sub Need To Work In All Workbook

Oct 11, 2013

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

View 4 Replies View Related

Private Sub To Check When Specific Value Is Entered?

Feb 25, 2014

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 Related

Disabling Private Sub Macro Temporarily

Jul 12, 2007

How 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?

View 9 Replies View Related

Private Sub Workbook_Open() Doesn't Execute

Feb 25, 2008

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.

View 9 Replies View Related

Call Private Sub Undefined Error

Jul 25, 2006

I 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.

View 3 Replies View Related

Exit UserForm Private Module

Dec 15, 2006

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







Copyrights 2005-15 www.BigResource.com, All rights reserved