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
ADVERTISEMENT
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
View Related
Jan 11, 2010
I know I've asked before but I can neither find my previous question or the answer.
So, once again.... is it possible to refer to a named range in a CSE array formula?
I know how I would type a formula that way -- but I would be happy to see an example.
Most importantly, will it always work? Or are there pitfalls and dangers?
View 3 Replies
View Related
Jan 2, 2008
I put all my named ranges in a seperate worksheet in the workbook.
On a different sheet I have all my data with references to the named ranges. But what it gives me is the cell information from the sheet on which the named range is located and not on the worksheet where I actually need the calculations to be done.
How can I make the named range refer to the cells in the worksheet in which it sits?
Worksheet 1
---------------
1
2
3
4
Worksheet 2
--------------
I name the function Red apples
RedApples =CONCATENATE($A1&"Red Apples")
Worksheet 3
--------------
=RedApples
=RedApples
=RedApples
Question #1
How do I make the name reference in worksheet 2 refer to
the cells located in the worksheet in which i use it. In other words, when I use RedApples in Worksheet 3, it gives me what is sitting in A1 in worksheet 2 instead of in A1 on Worksheet 1.
Question #2
How do I make the name reference in Worksheet 3 keep stepping down along Column A in Worksheet 1?
Formula at issue in actuality is
=IF($S5>0.149,Morethan15,IF(AND($S5<0.15,$S5>0.999 ),Morethan10,IF(AND($S5<0.999,$S5>0.0499),Morethan 5,IF(AND($S5<0.05,$S5>0),Morethan0,IF($S5<0,Lessth an0)))))
the morethan15,10,5,0 and lessthan0 is defined in the last worksheet
View 6 Replies
View Related
Aug 13, 2009
Is it possible to call a Private Sub from another Module?
View 2 Replies
View Related
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
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
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
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
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
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
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
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
Oct 1, 2007
I created a name in Excel 2002, Name = "NameToUse", Refers to = "Bill".
How do I get the value in VBA code?
Range("NameToUse").value ' doesnt work
NameToUse ' doesn't work
View 3 Replies
View Related
Oct 31, 2008
I have the following codes in which I am to refer a file and folder to do some further processes.
myfilename = "C:Documents and settingsacsMy DocumentsEntrymyfile1.xls"
folderPath = "C:Documents and settingsacsMy DocumentsEntry"
I want to enter these two paths in a sheet in my excel report file (For example, I am running the report from Report1.xls, in which there is a sheet name "Filepaths". In this,
in B5, I would like to enter the Filepath (B5 named as "FILEPATH")
in B6, I would like to enter the Folderpath (B6 named as "FOLDERPATH")
So that, if I am copying the folder to another area, I no need to change the code every time in the VBA editor. I can do changes in these cells and it will be taken as the path to run the code further.
View 2 Replies
View Related
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
Apr 12, 2009
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[-
View 9 Replies
View Related
Jul 15, 2014
I have a userform with a ListBox and I'm trying to refer to each particular item in the Listbox for a range but it doesn't work.
[Code] .....
View 14 Replies
View Related
Oct 4, 2011
I want to know all times this one presents the number 3 in the last 10 cells of the A column
For a static range I use this function
= COUNTIF(OFFSET(A16;-10;0;COUNT(A:A));3)
If I add a new cell which is the function for a dynamic range?
I can refer to the cell with this function = ADDRESS(MATCH(300;A:A);1)
but not as integrate it.
View 1 Replies
View Related
Jun 8, 2012
Dim k as string
K = "sheet1"
Sheets(k).select
This is the code 'm using
View 9 Replies
View Related
Jul 15, 2007
I am looking to Set an object as a Array, but i keep getting an error, and the book i have does not really go into Set Functions that much, so not sure if it can be done or not?
For d = 1 To 31 ' days in the month
Set Rng(d) = Range(sRng & ":" & eRng)
Next d
sRng andn eRng are already set by date, and I have Dim Rng() As Range at the top.
Can a Set function have a Array in it?
View 9 Replies
View Related
Jun 2, 2006
I need to create a named range on multiple sheets with the same named range & i cant figure out how to do this. EG :- I want to create a named range called "_SubUnitRows" on sheet1 starting from "A1:A50" & other named range again called "_SubUnitRows" on Sheet2 starting from "A1:A25" ...
View 2 Replies
View Related
Dec 19, 2006
I am looking for a way to delete all the range names in a worksheet, not the whole workbook. I have found several procedures that will delete all the names in an activeworkbook. For some reason it takes too long to run. Does anyone know how to handle a single sheet in VBA?
View 6 Replies
View Related
Apr 5, 2008
I have filtered a list, defined a range of the visible cells. Now I want to loop thru the range and process each cell. In the process I have to refer to the next visible cell. How can I achive this? both .Offset and .Item result in the next none-visible cell.
View 3 Replies
View Related
Jul 19, 2013
I'm trying to make my named ranges remember the values of the last active cells used within another named range. The purpose of this is to make my charts dynamically change dependant on two criteria selected. My spreadsheet currently updates itself as and when I change the active cell within a single named range, dynamically changing the chart data by using Lookup based on the active cells value. However I want to get away from having several charts showing, I would like to have a single chart which dynamically changes based on a second selection. So the first selection is for a department (Facility) which changes the chart data relevant to that department, the second selection is to dynamically change the chart shown for the pre selected department.
Picture2.jpg
Using the following code when updating just one criteria with several charts
VB:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Application.Intersect(ActiveCell, [MeasureType]) Is Nothing Then
[valMeasurePicked] = ActiveCell.Value [code].....
which works fine but I'm not sure how to add a second selection criteria because my code uses Activecell. I thought that the VBA needed to set the last used value of a range as a variable and therefore allow the second criteria to be selected but am not sure how to put it into practice.
View 2 Replies
View Related
Oct 25, 2009
if I can use a named criteria as well as a named range. In essence what I am looking to do is count certain cells that meet the criteria in a certain named named range,
View 9 Replies
View Related
Mar 14, 2013
Merge two columns into one list in excel
I would like to combine List1 and List2 into a 3rd named range called List3. I was wondering if this were possible without using any additional cells/columns (i.e. I don't want to use Column C like in the example shown in the link above).
Here's the formula from the example:
Code:
=IFERROR(INDEX(List1,ROWS(C1:$C$1)),IFERROR(INDEX(List2,ROWS(C1:$C$1)-ROWS(List1)),""))
I've played around with it, but could not come with any that worked.
View 3 Replies
View Related
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
Jan 24, 2013
Let's say i have 2 Modules on my VBA forms, is it possible to Copy all the Codes in Module 1 and Paste it to Module 2 by using a Command Button?
View 1 Replies
View Related
Jan 19, 2012
i got a question how i can make a msgbox in one module with 'Yes' linking to a different module.
such as: this is located in module2
Code:
If MsgBox("Do you want to activate module1?" & vbCr & _
"" _
, vbYesNo, "Choose") = vbNo Then Exit Sub
i want that vbYesNo different
No as in Exit Sub
yes as in activate Module1
View 5 Replies
View Related