Code Fails When Called From Private Sub

Aug 22, 2007

I'm having a hard time with this piece of

Private Sub Assign1Combo_Change()
If Range("ComboVisible") = False Then Exit Sub
Assign1_Download
End Sub

Symptoms:
- As soon as this is used, Excel/VBA can't select any range on the worksheet. For example, the following code (within the sub Assign1_Download) no longer works:

Range("firstdata").Select

Excel/VBA doesn't select that Named Range or any other range I try (ex. A1). - This problem only happens in Excel 2003. In Excel 2002 everything works fine (can make any selection).

View 5 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

Workbook Open Code Fails

Oct 4, 2006

I tried testing, msgbox displays the correct last modified file "MMO Activity Report 09-29-06.xls" in path D:MMOWorkfile but I was not able to open the workbook.

Sub testGetNewestFile()
MsgBox NewestFile("D:MMOWorkfile", "*.xls")
Workbooks.Open (NewestFile("D:MMOWorkfile", "*.xls"))

View 9 Replies View Related

Vba Code: Copy To Another Sheet Fails

Mar 25, 2007

Error:
Run-Time Error: 438
Object doesn't support this property or method.

Two things to note: This code was placed in the worksheet, something new I am trying and two the error line is not highlighting in yellow (as it normally does) indicating the line w/ the infraction.

Option Explicit

Sub QuickView()

Dim Wss As Worksheet 'Source Worksheet
Dim Wsd As Worksheet 'Destination Worksheet
Dim LRow As Long

Set Wss = Workbooks("TGSItemRecordMaster.xls").Worksheets(" Record Creator")
Set Wsd = Workbooks("TGSItemRecordMaster.xls").Worksheets("Quick View")

LRow = Wss. Cells(Rows.Count, "w").End(xlUp).Row - 4

Wss.Range("W3" & LRow).Copy Wsd("A3")

End Sub

[/code]

View 9 Replies View Related

Macro Code Fails On Other Computers/PC's

May 29, 2008

I have a workbook with macros that run on my laptop, but when I email the workbook to another user and the macro is executed I get a subscript out of range message?
Both Excel versions are the same.
Environments are the same.?

View 4 Replies View Related

Call Private Macro But Do Not Copy Code To New File

Apr 27, 2012

I would like to have something that will auto run the code in Module1 when the Excel File is opened, but I do not want to code tansfered into the file when it is saved in its location.

I don't mind if the code is tranfered to saved file if in fact I can make sure the code is not run when the new file is opened...

Everything is working as intended at the moment, but when openeing the saved file the entire macro tried to run again. This is what I do not want...

I currently have the following code in Module1.

Private Sub Workbook_Open()
'
' Format_Copy_&_Paste
'
Application.OnKey "^+r", "Warehouse_Cost_Summary"
'
Sheets("Sheet1").Select
Sheets("Sheet1").Name = "DataSet"

[Code] ..........

View 4 Replies View Related

Excel Code Works Fine But Error When Called From Access?

Apr 11, 2012

This code works fine when I run it in Excel.

Code:

Sub RemoveCodeAndSave()
'Remove all code from ThisWorkbook code module
ThisWorkbook.VBProject.VBComponents("ThisWorkbook").CodeModule.DeleteLines 1, _

[Code]....

I get the error "Run-time error 440: The specified dimension is not valid for the current chart type" why I am getting this. The macro does everything I want it to, except for throwing the error at the end.

View 3 Replies View Related

Chart Code With SetElement Fails In Pre 2007

Aug 22, 2008

I wrote this code so that someone else can keep track of a certain bond. It will provide him with returns and a chart between 2 periods. I wrote it on Office 2007 and it works for me, from the begining I wrote the code in an office 97-2003 compatible file. The worksheet is attached.

Sub Grafico()
Dim FechaGraficoInicial As Date 'Fecha de referencia para el rango
Dim FechaGraficoFinal As Date
Workbooks("Julius Baer.xls").Activate 'Para evitar un error, NO BORRAR
Worksheets("Precios").Activate
Columns("G:G").Select
Selection.ClearContents
Workbooks("Julius Baer.xls").Activate
Worksheets("Rentabilidades").Activate
FechaGraficoInicial = Worksheets("Rentabilidades").Range("B22")
FechaGraficoFinal = Worksheets("Rentabilidades").Range("B23")
i = 0
Condicional = 0 'Determina si el grafico se hace o no..........................

View 2 Replies View Related

Macro Code Fails When Run On Workbook On Server

Mar 11, 2008

I have used the following piece of code to stop error checking in my excel spreadsheet:


Option Explicit

Private Sub Workbook_Open()
' Application.ErrorCheckingOptions.BackgroundChecking = False
End Sub

The problem is - works fine on my computer, but when distributed on the server the folloeing error is returned:

Run-time error '438':
Object doesn 't support this property or method

View 9 Replies View Related

Excel 2007 :: Code Fails To Put Results In Cell

Jan 23, 2013

I have the equivalent of Vlookup code(I couldn't get vlookup to work correctly) I am using Excel 2007. I have an array 2 cols x 1652 rows. I have another column of 6264 items. If a text item in the first column of the array matches a text item (minus 3 characters) in the longer column, I place the matching row from the array next to the item in the longer column. Whats not working is that the text never gets put in the cell.

Code:
Sub Macro1()
'
' Macro1 Macro

[Code]....

View 7 Replies View Related

Show Custom Error Message If Opening Workbook Macro Code Fails

May 17, 2008

I cannot figure out how to get my error handler to work, or actually, not work. It seems to work fine when there is an error, but the code still gets read even when there was not an error. Basically, I am trying to open a file, which may or may not be there. When it is not there I want a message to pop up informing the user. However, when the file is there and it opens, the error handler still gives the message box. Any ideas what I am doing wrong?

Private Sub btnOK_Click()
Application. ScreenUpdating = False
Dim LCSfile As String
LCSfile = frmSelectFile.Listbox1.Value
On Error Goto ErrHandler
Workbooks.Open Filename:=sPath & sDate & "" & LCSfile & "QUANT.CSV"
ErrHandler:
MsgBox ("File is not quantitated. Please select another file.")
Application.ScreenUpdating = True

End Sub

View 2 Replies View Related

"PC" To Show Up If I Type A Sentence Containing "Called Parent", "Called Dad", Or "Called Mon"

Dec 2, 2009

I need "PC" to show up if I type a sentence containing "Called Parent", "Called Dad", or "Called Mon". Here is what I'm trying.

View 2 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

Macro Called For Copying

Feb 23, 2007

I have a macro called "Copying" and this runs perfectly well when run on its' own.

I have now created the following peice of
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

If Sheets("form").Range("B14").Value x Then
x = Sheets("form").Range("B14").Value
End If
Application.Run "Copying"


End Sub
Which (should) run the "Copying" macro if cell B14 is changed........here is my problem.

It seems to run this macro over and over again. How can I get it to just run it once?

View 9 Replies View Related

Calander Control Called In VBA

Jan 9, 2008

I'm using the calander control in Excel which is called in VBA when a user clicks on a cell in a range - the code is as follows:

' Calander for Activity Start Date and end dates
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, [H11:I30,H33:I52,H55:I74,H77:I96,H99:I118,H121:I140,H143:I162,H165:I184,H187:I206,H209:I228,H231:I250,H253:I272,H275:I294 ,H297:I316,H319:I338,H341:I360]) Is Nothing Then
If Intersect(Target, [K11:L30,K33:L52,K55:L74,K77:L96,K99:L118,K121:L140,K143:L162,K165:L184,K187:L206,K209:L228,K231:L250,K253:L272,K275:L294 ,K297:L316,K319:L338,K341:L360]) Is Nothing Then
Calendar1.Visible = False
Exit Sub
End If
End If...........

View 9 Replies View Related

Can A Subroutine Be Called Within A Function

May 12, 2006

1. Can a Subroutine be called from within a user-defined Public Function? How?

2. Is there a difference between calling a subroutine with a 'Call Sub_Name' statement, vs. calling the subroutine with an 'Application.Run'(?? or similar) statement?

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

Determine Which Check Box Called Procedure

May 21, 2009

If I have several Forms check boxes assigned to the same procedure, is it possible to tell which check box called the procedure?

View 6 Replies View Related

Function Being Called At Inappropriate Time

May 29, 2009

Function being called at inappropriate time
I have the following code in the active worksheet:

View 4 Replies View Related

Called Or Directly Excecuted Routine

Dec 10, 2009

I want to thank you all for the solutions/support I received in completing my (for me) difficult workbook.

I still have a tricky problem. In the example below, can Multibeep "know" when it is being called from Beep versus being excuted directly? And if so can I direct a different sequence?

View 10 Replies View Related

Passing Value Of Convert To Other Procedures That Are Being Called?

Jul 2, 2012

I am running this code it is rather long, but I need to show it all ?

Code:
Public Sub Monday()
Dim mName() As Variant
Dim lName() As Variant
Dim fName As String

Call lower(CStr(mName(q)), fName, CStr(lName(q)))

[Code] .........

How to do is to pass the value of convert to the other procedures that are being called? As you can see I know how to pass variables down to "Sub-routines" but how would I pass the variable up?

View 8 Replies View Related

Series Of Subs Called From Function

Apr 15, 2013

I have a series of procedures I am calling from a function that each run fine when executed individually. These procedure are titled: DataValidation, Test1, Test2

The function will not run past Test2- I do not get the msgbox "Stage 2"

Code:
Public ArrayD
Public ArrayD2 As Variant
Public RngD3 As Range

Public Function Test(arg2 As Range)

DataValidation arg2

[Code] ............

View 4 Replies View Related

Excel Called From VBS Does Not Fully Exit

Nov 5, 2009

I am trying to sort a csv file through a VBScript. My problem is that Excel continues to run as a process on script completion. Running multiple variation of this script results in multiple instances of Excel being present in the WinXP Process Manager.

Set xlObj = CreateObject("Excel.Application")
xlObj.Visible = false
xlObj.Workbooks.Open "C:Test.csv"
xlObj.ActiveWorkbook.ActiveSheet.Range("A1").Sort xlObj.ActiveWorkbook.ActiveSheet.Range("A1"),,,,,,,0
xlObj.ActiveWorkBook.Save
xlObj.ActiveWorkBook.Close true
xlObj.quit
set xlObj = Nothing
As a second part to my question, is there any way to modify the code to allow multiple field sorts, i.e., A1 is Primary, C1 is secondary?

View 9 Replies View Related







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