Range As Parameter In Function Declaration
Aug 3, 2009I have a formula that hides rows within a range for a sheet.
View 2 RepliesI have a formula that hides rows within a range for a sheet.
View 2 Repliesis there anyones know what's the meaning of 1 in this formula
MATCH(1,('Data Issues'!$A2=Sheet1!$A$2:$A$68)*('Data Issues'!B2=Sheet1!$B$2:$B$68),0)
I though I could do this with a nested IF statement but it is too cunfusing for me. What I am trying to accomplish is this:
Experiment
Is Steward
EU ID
Location
Data Quality
GE
Entry Order
[Code] ........
I want to have a screen pop-up asking me what my limit < would be for column "ESTCNT" so if I put in 25 or any other number that it would highlight all the rows that are less than 25, then look at the row above and below and if it matches the same number (that is in the cell "Range" of the highlighted column) in column "Range" then copy that row to a new sheet. Meaning all tha rows that match the "Range" would be in the same new sheet.
The rows might be different lengths and that there will not always be a number in cell "ESTCNT". Column headers will always be the same but might not be in the same column each time. And if it is not to hard once it is completed to find column "SPPLOT" in the new sheet created and asking what I want to autofil the column with.
I have the following info in a table:
name | doc date | doc value
a | 2009/01/01 | IN111
b | 2009/02/04 | IN222
c | 2009/02/05 | IN333
a | 2009/01/05 | CN111
d | 2009/03/01 | IN444
b | 2009/03/01 | CN222
a | 2009/04/01 | IN555
Firstly, I need to find the LAST DOCUMENT DATE for "a" where #doc_value starts with IN*** (invoice). Manually, I can see that it would be "2009/04/01", but my spreadsheet runs 6000+ entries. I need a function to do this.
Secondly, I need to find the corresponding #doc_value for that date (in this case, IN555).
I have a combobox in a excell sheet. It is possible to pass a parameter in the input range instead of Parm!$B$1:$B$10
View 2 Replies View RelatedThe following is not working for me with an overflow #6 error.
Sub multiplythis()
Dim highnumber ' As Long, I've tried Double, Long and now Variant
highnumber = 50 * 250 * 300 * 400 * 20
End Sub
I've been asked to produce a spread sheet that will calculate split payments for a list of households built by our company. The bill amount will be given to us by the power company, and the basis for bill separation is base on the billing period, and the date of house settlement.
The codes I've produced are written below, however I couldn't get it to run properly. The software keeps on telling me that my variables aren't declared correctly.
I've attached all my codes below for your reference.
Public Start_Date As Date
Start_Date = Worksheets("Sheet_Input").Cells("D", 1).Value
Public End_Date As Date
End_Date = Worksheets("Sheet_Input").Cells("F", 1).Value
Public Total_Date As Integer
Total_Date = Worksheets("Sheet_Input").Cells("H", 1).Value
Public aAverage As Integer
aAverage = Worksheets("Sheet_Input").Cells("B", 3).Value
Public bAverage As Integer
bAverage = Worksheets("Sheet_Input").Cells("D", 3).Value
I am getting "Duplicate Declaration" error while running my code. Cant post entire code as its too long but i am pasting the problem line.
View 12 Replies View RelatedI'm using a public declaration for a worksheet but I seem to have to initialize it in each routine. Is there a way to set it and leave it? So in a module I have:
View 4 Replies View RelatedI have some code that runs a mouse event and keeps my computer active when I'm away. It works on my 32-bit computer, but doesn't work on my 64-bit. What is the correct syntax to have it work on a 64-bit?
I get the error: "declare stmts must be updated for 64 bit and marked with PtrSafe attribute."
BTW, I already tried changing "user32" to "user64", that didn't work.
Code follows:
Public Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long
Public Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = &H2
Public Const MOUSEEVENTF_LEFTUP = &H4
Dim TimerActive As Boolean
Sub KeepWindowsActive()
[code].....
using win 7.
I have two issues in SumProduct formula.
1.Formula Def.Cells(c, d).Formula = "=SUMPRODUCT(--(Severity =" & """" & severity_3 & """" & "),
--(OFFSET(Severity,0,4)=" & """" & module & """" & "))"
Where severity_3= Shipping
There are many fields like Shipping, Shipping-UI, Shipping-BE.
I want the formula to consider all the above when severity_3= Shipping and take the count & not only consider Shipping(Shipping*) .
2.Formula test = "0 - Unclassified" Or "Alpha Testing" Or "Beta Testing" Or "Functional - Interface" Or "Functional - Report" Or "Regression Testing" Or "Requirement Review"
when i use the above formula , it is displaying the message "Run-time error'13':Type mismatch There are spaces in the criteria i have used but i am not sure how to resolve this
I suspect the array variables declaration in the following example is the problem.
The array Function MyRoots() incorrectly returns 0.0 results to cells I11:J13.
cell B8::3
cell B9: myTrue
cells B11:C14 numerical values
cells I11:J13:: array function {=MyRoots(B11:C14, B8, B9)}
Function MyRoots (a, m As Integer, polish As String)
ReDim a(m + 1, 2) As Double
ReDim roots(m, 2) As Double
Dim j As Integer, its As Integer
Dim x(2) As Double
ReDim ad(m + 1, 2) As Double
......................................my code............
For j = 1 To m + 1
ad(j, 1) = a(j, 1)
ad(j, 2) = a(j, 2)
Next j
......................................my code............
Call Laguer (ad, j, x, its)
......................................my code............
roots(j, 1) = x(1)
roots(j, 2) = x(2)
......................................my code............
MyRoots = roots
End Function
Sub Laguer (a, m, x, its)
Dim x1(2) As Double
......................................my code.......................................
x(1) = x1(1)
x(2) = x1(2)
......................................my code............
Exit Sub
End Sub
I have a smattering of experience within various programming languages, but am still coming to terms with the basics of VBA. I am trying to declare a global variable, assign it a value, then use that global variable. Within 'ThisWorkbook' I have the following...
Public myText As String
Private Sub Workbook_Open()
myText = "Hi There"
End Sub
...and in the Microsoft Worksheet Object Sheet1 (Sheet1) I have...
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
MsgBox myText
End Sub
Now, my understanding of this code is that upon opening the workbook, myText variable will be declared, and then assigned the value "Hi There". Then, once I have clicked anywhere on Sheet1, a message box will appear stating "Hi There". Problem is, the message box is blank. This is all fine, except I want the message box to state "Hi There". What am I doing wrong? Is the variable declared (publically) correctly? Am I assigning the public variable the value correctly?
Am I referencing the public variable correctly in the Worksheet_SelectionChange procedure correctly?
I am using the format of using variables for declaring file paths and document names in VBA however I want to make sure I am doing it properly...
Dim Server, VersionName As String
Server = Worksheets("Calculation Matrix").Range("CalculationMatrix_Server").Value
VersionName = Worksheets("Calculation Matrix").Range("CalculationMatrix_VersionName").Value
ActiveWorkbook.SaveAs Filename:="" & Server & "uploadcomplete" & VersionName & "", FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
Should these variables be declared as String?
I am trying to run a VB script that will copy data from 3 worksheets and past it into 3 New worksheets, sort that data into alpha order then delete all rows containing Zeros that may be found in Column B, Then copy that data from the 3 New worksheet back into the original 3 worksheets.
The copying and sorting of the data from one sheet to another is easy. The problem is trying to delete the zeros found in column B once its been copied over into the 3 New worksheets.
The script I am using to delete any Zeros found in Column B is below.
If I try to use this script more then once, so that I can delete all the zeros found in column B on all the New worksheets I get this error “Duplicate declaration in current script”
Is there a way for me to refer back to this script instead of me trying to past it more then once within the VB script.
Application. ScreenUpdating = False
Application.Calculation = xlCalculationManual
Const StartRow As Long = 1 'Row to Start looking at
Dim StopRow As Long
Dim Col As Long
Col = ActiveCell.Column
StopRow = Cells(Rows.Count, Col).End(xlUp).Row
Dim cnt As Long
For cnt = StopRow To StartRow Step -1
If Not IsEmpty(Cells(cnt, Col)) Then
If IsNumeric(Cells(cnt, Col)) Then
If Cells(cnt, Col) = 0 Then Rows(cnt).Delete
End If
End If
Next cnt
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Please see attached workbook. You will understand it better once you see the workbook and the VB script in it.
Hopefully this isn't too vague, but almost every project I've worked on so far has not recognized Public variables in all modules. I've constantly been searching for exceptions to this rule that could be contributing to this issue but haven't been successful.
I have read a million times that declaring a variable as Public makes it visible to all modules and preserves the value throughout. I've also read that if you edit code or reset your project, the values may be lost. I also know that if you try to use a variable before you give it a value (or for object variables set it = to something), it doesn't have a value yet. But all this applied, I'm still not getting Public variables to be consistently recognized or stay with the value I want them to have throughout the lifetime of my project (while the workbook is open)
My specific current issue (one of many so far) is that I have 4 command buttons within a worksheet object. Each triggers a different group of procedures, some of these are user forms. In the first button, I create two worksheets one to contain the current fiscal period "Options" the other for "Summary" of all the totals etc... (all financial data). In this first userform, triggered by the button, I allow the user to name these worksheets: like Summer2007Options or Summer2007Summary and I declare these publically as object variables OptSheet and SumSheet. These variable names and sheets are recognized for the next 2 buttons but now that I'm on the fourth, I have object variable not set errors when I try to refer to this variable.
I get an error: Duplicate declaration in current scope? The formula calculates the compound annual growth rate.
View 5 Replies View RelatedI have the following code which performs the same action on 2 different tabs within the same workbook:
Dim Rng As Range, Dn As Range
Set Rng = Range(Range("O1"), Range("O" & Rows.Count).End(xlUp))
Rng.NumberFormat = "@"
For Each Dn In Rng
If Len(Dn) < 7 Then Dn = String(7 - Len(Dn), "0") & Dn
Next Dn
i get the following error:
Compile Error: Duplicate declaration in current scope
I am trying to automate the creation of 3 pivot tables. At first I was having a problem with deselecting all items in the drop-down except one, then I found the code to fix it.
I replaced this code:
ActiveSheet.PivotTables("PivotTable15").PivotFields( _
"Beta")
.PivotItems("Escalated").Visible = False
.PivotItems("Hang Up").Visible = False
.PivotItems("New Hire Requests").Visible = False
.PivotItems("No Trouble Found").Visible = False
.PivotItems("Priority Exchange").Visible = False
[code].....
This fixed the problem, but there are still two other pivot tables that need to be created after this first one. I scrolled down through the code and deleted the other code blocks for the selection of the PivotItems and replaced it with the code above, but then when I ran it I got the "Compile Error: Duplicate Declaration in current scope".
I read more through the forum and realize that it's because VBA is dimensioning it twice, and I read that you're supposed to Dimension at the beginning of your program, but how do I implement this into my coding?
I can't dimension literally at the start of the code, there is some formatting that needs to take place first. (Basically I paste in a bunch of data into Sheet1 of my workbook, center it, space it out, then insert a pivot table into the pre-existing Sheet2 based on that data, filtered on the blank entries in Column N. Then I need to create ANOTHER pivot table based on that same data in Sheet1, but filtered on the blank entries in Column O. Then I center the words in the Pivot tables' headers in Sheet2, and finally I need to create one last pivot table on pre-existing Sheet3 based on the data on Sheet1, filtered for 2 specific entry types in Column N.)
In Mr Excel's Pod Cast on April 12th, he showed how to use the OFFSET function to define a range inside a SUM function. Then he had Conditional Formatting that would highlight the range that was being summed. Can anyone tell me what the formula would be inside the Conditional Formatting dialog box to get the OFFSET range to have a certain format?
View 9 Replies View RelatedI have a function
VB:
Function f1(Matrix As Range)
'Does something and returns f1 = a double
End Function
And a second function which defines and constructs a matrix of doubles to use as an argument in f1 to return a double:
VB:
Function f2(dD As Double)
Dim MatrixRed() As Double
Redim MatrixRed(1 To dD, 1 To 10)
For i = 1 To dD
For j = 1 To 10
MatrixRed(i, j) = i * j
Next
Next
f2 = f1(MatrixRed)
End Function
I get an output error (#VALUE). I think it has something to do with MatrixRed not being a range anymore?
Here it goes.
My spreadsheet is populated by data coming from MS Query, i'm entering a parameter value to display the desired data in my spreadsheet. My problem is, i have to close and open the file to have the parameter prompt so in that case i can enter the parameter value.
Is there anyway to call the parameter prompt so i will not open and close the file, its really time consuming...
If possible, i just want a command button that calls the parameter prompt.
I have a function which has to contain the name of a combo and use it with some given parameters, here's my example: ...
View 8 Replies View Relatedadd parameter to this macro and at the end the process to index the highest result at the end, is that possible?
Here is the macro;
Code:
Sub Macro()
Range(Selection, Selection.End(xlDown)).Select
Calculate
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range
[Code]..
to run 5000 times
Looking for a formula that gives the 1st - 5th day of a month, using the day name, e.g. "First Monday of March 2009" returns "2". Even better is if it could accomodate previous and following months, e.g. "First Monday of Next Month" returns "6". 3
View 9 Replies View RelatedI can run my query from within MSQuery something like
like %RESISTOR%
and it works fine.
However I cannot use %RESISTOR% on the excel sheet as a parameter.
is it possible to update a query using a parameter in this way? Maybe getting VBA to actually update the query manully.
I want know how to pass a parameter through a cell for date in the following url
http://fc-web-phl1-101.phl1:8090/gp/...runReport.y=10
I’m trying to use the SUMIFS function in Excel 2007 to evaluate the following formula:
{=SUMIFS(range to sum, range to evaluate, evaluation criterion)}
The range to sum is A1:A10, the range (dates) to evaluate are in B1:B10, and the evaluation criterion is that the date is before 31/10/1999.
So my formula looks like this:
{=SUMIFS(A1:A10,B1:B10,”<31/10/1999”)}
This works fine, but how do I refer the 3rd argument in the function to a date in a particular cell rather than typing in the date specifically?
I was just recently forced to create my first UDF and after how well it worked I now am very interested in learning more. I am trying to create a function to sort a range by the values in a specific column and return the range. I know this should be really simple but for some reason my code dies whenever it gets to my inner-most loop. I need to use this in a larger function but for now this is my only question. I did find that Excel 2007 has built in Functions for this but my company still uses 2003.
My
Public Function SortRange(rngToSort As Range, valCol As Integer)
Dim Swapper As Variant
Dim i As Integer, _
j As Integer, _
k As Integer
For i = 1 To rngToSort.Rows.Count
For j = 1 To rngToSort.Rows.Count - i
If rngToSort(j + 1, valCol) < rngToSort(j, valCol) Then
For k = 1 To rngToSort.Columns.Count
Swapper = rngToSort(j, k)
rngToSort(j, k) = rngToSort(j + 1, k)
rngToSort(j + 1, k) = Swapper
Next k
End If
Next j
Next i
SortRange = rngToSort
End Function
I have a a table at the top of my worksheet which is a breakdown of performance. (Table 1), i would like Table 2 to roll up performance using a =SUMIFS calculation. However number of rows in table 1 may vary.
View 2 Replies View Related