Macro Referencing Named Range In Worksheets Private Module

Sep 12, 2006

I'm having trouble calling a defined range within a VLOOKUP function in VBA. If the named range is located on the same sheet within which you are running the macro, everything runs fine and all is well in the world.

However, after I relocated the range to a separate sheet (a 'SourceData' sheet to tidy up the user interface sheet), I was getting the following error message:

Method 'Range' of object '_Worksheet' failed

The name is correctly defined - Range("DaysInYear").Select still picks up the correct selection - it's just the VLOOKUP will no longer function correctly.

Here is part of the macro's


For I = 1 To NumberOfDays
Range("A1").Value = DateAdd("d", -(I - 1), EndDate)
If Application.VLookup(Range("A1"), Range("DaysInYear"), 3, False) = 1 Then
If Application.VLookup(Range("A1"), Range("DaysInYear"), 4, False) = 0 Then
ActualNumber = ActualNumber + 1
End If
End If
Next I

View 9 Replies


ADVERTISEMENT

Refer To Named Range In Private Module

Nov 10, 2006

I've got a problem referring to a named range in another worksheet.

Private Sub test()
Dim var_StartWeek As String ' 0740 This is the value I make a lookup for
Dim var StartWeekNr As Integer ' 40 and get this as a result

'*** Here is the named range in another worksheet (It doesn't work)
Set rng = ActiveWorkbook.Names("WeekData2").RefersToRange
var_StartWeekNr = WorksheetFunction.HLookup(var_StartWeek, Range("rng.Value"), 4) ' I'm doing something wrong here...

'*** If I have the named range in the same worksheeet it works fine
'var_StartWeekNr = WorksheetFunction.HLookup(var_StartWeek, ActiveSheet.Range("WeekData"), 4)

View 3 Replies View Related

How To Call A Private Module.Macro From Within ThisWorkbook

Oct 17, 2003

When in a ThisWorkbook macro, I want to call a sub/macro in a Module. Usually you can just do a CALL MACRO1, and it will find it. But my MACRO1 is Private as I don't the users to be able to do a Tools, Macro, Macros and see it. So I don't want to make it a Public macro. So how do I call the private sub/macro from within ThisWorkbook?

Can I proceed the sub/macro's name with the name of the module, kind of like CALL MODULE1.MACRO1? Or do I have to make it public?

View 9 Replies View Related

Run Macro That Resides In A Private Sheet Module

Mar 26, 2008

I have a sheet that has a macro on it, I would like to run that macro programaticaly but Im not able to call it using Call mymacro type of code. The code that calls the macro resides in a module and the macro is in a sheet. Obviously they are not talking, is there a way to run it remotely without moving the macro into the module?

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

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

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

Access Private Module Of The Workbook. 2007

May 15, 2008

I want to write some code that runs everytime the workbook is initialized. I found out that the code should be placed in the following "Private Sub":

Private Sub Workbook_Open()
'My code
End Sub

I know that this code should be placed in the Private Module of the Workbook! I just can not find where is the Private Module of the Workbook in Excel 2007... =/

View 3 Replies View Related

Referencing Named Range Without Using Worksheet Name

Aug 13, 2014

I want to export data from a set of named ranges in workbook x to another set of ranges in workbook y. The names of the ranges to be exported from and to are spesified in a table "Table_Export". Problem is I do not want to spesify in what sheets these respective ranges are located, seeing that I do not know the actual sheet names. But since the ranges are global it should somehow be possible to reference them in vba without referencing the respective worksheet?

The relevant code can be found below where either of the two 'commented lines within the if statement are what I want to accomplish.

Dim x As Workbook
Dim y As Workbook
Set x = ThisWorkbook
Set y = Workbooks.Open(Range("Export_to").Value)
Dim export_control As ListObject

[Code] ....

View 2 Replies View Related

How To Delete Another Excel Private Module Of Workbook Object

Jul 9, 2013

How to delete another excel private module of the Workbook Object (ThisWorkbook) VBA codes of the workshook event.

This code to run from my PERSONAL.XLSB
Sub Macro1()
Windows("Book1.xls").Activate
ActiveWorkbook.Vbproject

Don't know what other codes I need to put after this
End Sub

This code to be deleted via Macro1 above code
Private Sub Workbook_Open()
Call CreateMenu
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call DeleteMenu
End Sub

View 2 Replies View Related

Pass Array Elements To Private UserForm Module

Mar 28, 2008

I am trying to pass a string array into a form. I have added a member string array to the form, and a property to "Let" the array in the the member array.

Private sFormString() As String

Property Let FormString(value() As String)
sFormString = value
End Property

I can pass a string in using a procedure:

Sub StringArrayTest1()

Dim TestString() As String
Dim frmString As FString

but I cannot "modulate" the code, or else I get an internal error (error 51). I.e. this code doesn't work:


Sub StringArrayTest2Mod(TestString() As String, frmString As FString)

frmString.FormString = TestString

End Sub

Sub StringArrayTest2()

Dim TestString() As String
Dim frmString As FString

Set frmString = New FString
Redim TestString(1 To 2)
TestString(1) = "Cat"
TestString(2) = "Dog"

Call StringArrayTest2Mod(TestString, frmString)

End Sub

Does anyone know why this happens? Obviously, in the example code its not an issue, but the application I'm using this for is more complex, and some modulation here would be good.

View 9 Replies View Related

Referencing A Named Range Or Sheet Dynamically?

Apr 19, 2013

I have a challenge I'm trying to surmount. I have an excel sheet in which I want to be able to select Zone codes from a drop down, click on a link "search" which takes me to a place in the document that has been named according to the Zone code i pick in the drop-down. I want to achieve this using only formulas as i'm distributing the file to a wide audience who are not versed enough with computers to know how to enable macros.

View 3 Replies View Related

Loop Range To Create New Worksheets Named For Each Row?

Jan 6, 2014

i have a range of rows that change (could be 10-100) how do i loop the range to create new worksheets named for each row?

View 3 Replies View Related

Excel 2003 :: VBA To Add Worksheets Named For Items In Range?

Jan 17, 2012

I some code that reduces a long list of dates from one source of data (in its own worksheet) down to a unique list of dates (on another worksheet). I need to create a new worksheet for each date in the range (named for the date), and then allocate each line item for that date in the source data into its repsective worksheet.

I'm using Excel 2003.

View 3 Replies View Related

Keeping Track Of Which Macro Is In Which Module Since You Can't Rename The Module?

Mar 27, 2009

After all the awesome macros I've obtained with the help of all of you, I now have over 30 macros, each in its own module. I have tried without success to re-name the modules with no luck. How is everyone organizing these?

View 2 Replies View Related

Macro To Find Named Worksheets In Workbook And Delete?

Nov 27, 2012

I need macro to find worksheets (tabs) starting with word 'sample' in name and delete all instances of worksheets starting with that word.

View 1 Replies View Related

Macro To Pull Data From Dynamic Named Multiple Worksheets Weekly Into A Master Sheet

Jul 11, 2014

Attached is a master metrics deck, where data needs to be refreshed every week, from two different workbooks.

The catch is, the two parent workbooks would be new versions every week (data would be same format, and style within), but file name would change each week, for eg: for 1st workbook, 'XXX_Weekly_Week24.xlsx' to 'XXX_Weekly_Week25.xlsx' and so on.

for 2nd workbook, 'YYY_Weekly_Week24.xlsx' to 'YYY_Weekly_Week25.xlsx' and so on.

In the master metrics deck, a consolidated vew of some of data from workbook 1 and workbook 2 is presented for each week.

This master file would remain same, and only be refreshed each week (preferably with a button on its sheet "REFRESH!!")

Next, need to manually change cells C2:G2 each week to reflect week titles correctly.

For e.g.: week6 would show week 1 through week 5, but during week7, it needs to show week 2 to week 6. Only last five weeks of data any given time.

The first datarows of each set are conditionally formatted (they are compared with other rows in the set and need to reflect danger values, good values etc) (I have done that already).

View 1 Replies View Related

Referencing With Named Ranges

Apr 22, 2009

Ok I have been trying to figure this out for way to long. Say I have a list of values in A1:A4. I have named this range MyRange. If I wanted to refer to this range somewhere else in the workbook and enter =MyRange it will only work provided the "=MyRange" is in the same rows as the original data.

For example if I enter MyRange in cells C1 through C4 it would mirror the data in column A. But if I enter MyRange in C5:C8 I would get a #Value error. Does anyone have any ideas to make this more of an absolute reference.

Basically anywhere I enter MyRange into a cell I want to see A1. If i drag that formula down I want to see A2, A3, A4, etc....

View 9 Replies View Related

Tab Named By Referencing A Cell Within A Worksheet?

May 6, 2008

Is it possible to have a tab named by referencing a cell within a worksheet?

View 9 Replies View Related

INDIRECT And Named Ranges Referencing Closed Workbook

Oct 4, 2005

I have tried using PULL from Harlan Grove's posts to workaround this but am coming up with #VALUE errors.

Here's what I have:

Column B contains the acct # being referenced e.g. 5230
Column E="_"&Br where r is the row #
Column F=MATCH($B$3,INDIRECT(Er&"Rows")) where _acct#Rows is a named
range referring to an external workbook e.g. _5230Rows
Columns G-R=INDEX(INDIRECT($Er),$Fr,COLUMN(G$6)) where_acct# is a named
range referencing an external workbook e.g. _5230

I thought that INDEX($Er, $Fr, COLUMN(G$6)) should work in Columns G-R however it returns #REF!

I need a solution to replace INDIRECT so I do not have to have both workbooks open together. The named ranges are static, but reference external workbooks.

View 13 Replies View Related

Module To Apply To All Open Worksheets

Jun 30, 2009

I have a module, which lists, by date, the number of instances of certain words as defined at the top of the column.
Anyway, this works fine - it operates on all sheets of a certain name type:

View 10 Replies View Related

Macro To Add Row In Named Range

Dec 30, 2008

Macro to add in a row in a named range, at the bottom of the range. the code i currently add in only to a certain row i need to add into a named range at the bottom.


Sub AddPersonnel()
With Sheets("DOR")
.Unprotect Password:="techedit"
Rows(56).Insert
Rows(55).Copy Destination:=Range("A56")
.Protect Password:="techedit"
End With
End Sub

View 9 Replies View Related

Sort Named Range Within Macro

Dec 8, 2011

I have a named range that is being updated via a macro. After the update, I want the list to be sorted. The named range is "Projects". This name is not a variable...it is a named range within Excel itself.

Any code to sort this at the end of my existing macro.

View 1 Replies View Related

Define Named Range In VBA Macro

Dec 29, 2009

I am trying to define a number of ranges in different sheets using VBA I am using the follwoing syntax but I am getting a 1004 error:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)

ThisWorkbook.names.Add Name:="Test", RefersTo:=Worksheets("Sheet1").Range("E6", Range("E6").End(xlDown))

End Sub

As long as I have sheet1 active, it works. If I have another sheet active and change smt, i get the error.

The code is located in the ThisWorkbook object.

View 6 Replies View Related

Macro: Re-Define Named Range

Nov 21, 2006

How can I redefine name of the cell? This is what I have tried and not work

intWDColumn = Range("rngWaterDepthStart").Column + 3
intWDColumn = intWDColumn + 1

strNameRange = "rawData!R7C3:R7C" & intWDColumn

ActiveWorkbook.Names.Add Name:="rngWaterDepthStart", RefersToR1C1:=strNameRange

and the cell name have define to ="rawData!R7C3:R7C7" which the "" stop the rename working I belive.? What I want is to add or reduce extra column into the name depends on macro.

View 4 Replies View Related

Macro - Add Data To Existing Named Range

Mar 7, 2014

I have a named range "ABC", range is ("A1", "A3", "A5"). Now I need to use Macro to extend the range to ("A1", "A3", "A5", "A7"), that is, adding "A7" to the existing named range "ABC".

View 1 Replies View Related

VBA Macro To Include Cell In Named Range

Mar 8, 2009

In my sheet I have a range on the go called 'cells_replen', I then need to search through the sheet and if a cell matching a given criteria is found I want to add it to the named range. The idea is that when I've done all the adding I can just select the range and then go back through the cells later on without searching for them all over again. The first code that declares the first cell I need in the range is:

ActiveWorkbook.Names.Add Name:="cells_replen", RefersTo:=Range("A3")

That works fine, I can also manually add cells into the range as below:

ActiveWorkbook.Names.Add Name:="cells_replen", RefersTo:=Range("cells_replen, A9")

No problem if I want to just add 'A9' but because I'm searching through the sheet, I need some way to just add 'ActiveCell' or similar.

View 4 Replies View Related

Determining If Cell Is Part Of Named Range And What That Named Range Is?

Aug 16, 2014

Let's say you have a named range, Rng1, which consists of cells A1 & A2. In vba how would you report back what, if any, named range the following cells resides:

Code] .....

here are multiple named ranges so using intersect is not feasible. Essentially, through code, I will be given a range and I need to determine if that range if part of a named range.

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







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