Summing Data In A User Defined Range
May 3, 2007
I have a spreadsheet which links to an external source, runs a sql msquery and retrieves data based on dates selected by the user from two drop down lists. From Date and Date To.This works fine. However I also need to total any fixed data which resides in the same spreadsheet based upon the same dates selected. The end user selects 2 dates , say 15/04/2007 (this relates to a week number,week15)and 28/04/2007(week 17)
A column of data lists the week numbers (in cells A3 - A22) and next to this their respective production quantities in cells B3-B22.
I now have a problem in totaling the production quantities in the worksheet as my user is not just selecting the week numbers 15 and 17 but 15,16 and 17.
qty
week 15100
week 16123
week 1789
How do I sum from 15 to week 17 inclusive or any other range selected?
View 7 Replies
ADVERTISEMENT
Aug 5, 2008
I am in need of creating a User Defined Function in Excel that will sum numeric values based on two text criteria. I have a large set of data in an Excel worksheet that includes a column for " Market Type" and a column for "Location ID". I would like to develop a User Defined Function that allows a new or inexperienced user of the template to use the User Defined Function to select first a "Market Type" then select a "Location ID" and get the sum of the amount those values represent. A SUMPRODUCT function in Excel works for this, but can be awkward or intimidating for a new or inexperienced user. For that reason, I am specifically looking for a User Defined Function that will simply the formula for them while at the same time maintaining the degree of accuracy I need.
View 9 Replies
View Related
Feb 13, 2009
I would like to alter this code so that the user chooses the column where the numbers are. They aren't always in column D....
View 9 Replies
View Related
Dec 4, 2012
Passing Named Range into User Defined Function
MrExcel.com | Excel Resources | Excel Seminars | Excel Products mcm91201
Depending on time of day and computer I am sitting in front of I am using:
WinXP Pro SP2 with Excel 2003
Win7 Pro SP2 Excel 2007
Win7 Pro SP2 Excel 2010 on PC
Win7 Pro SP2 Excel 2010 on Mac Mini running Boot Camp
OSX Excel for Mac 2011
I have only tried this on Win7 Pro SP2 Excel 2007 but need it to work on all.
I enter the values 0, 1, 2 ... 89, 90 in cells A1 to A91
I select A1:A91 and name the range 'angle'
I create a user defined function:
Public function sindeg(value As Double) as Double
sindeg = sin(worksheetfunction.radians(value))
end
I want 'value' for the function in a cell to be replaced by the corresponding value in the same row (or column) in the named range 'angle'. For example (using commas as column separators). This works for Excel functions like sin, cos, radians, etc.
********** Worksheet Contents **********
A1 = 00, B1 = sin(radians(0)), C1 = sin(radians(A1)), D1 = sin(radians(angle)), E1 = sindeg(0), F1 = sindeg(A1), G1 = sindeg(angle)
A2 = 01, B2 = sin(radians(1)), C2 = sin(radians(A2)), D2 = sin(radians(angle)), E2 = sindeg(1), F2 = sindeg(A2), G2 = sindeg(angle)
A3 = 02, B3 = sin(radians(2)), C3 = sin(radians(A3)), D3 = sin(radians(angle)), E3 = sindeg(2), F3 = sindeg(A3), G3 = sindeg(angle)
......
A91 = 90, B91 = sin(radians(90)), C91 = sin(radians(A91)), D91 = sin(radians(angle)), E91 = sindeg(90), F91 = sindeg(A91), G91 = sindeg(angle)
Column A = input. Columns B, C, D, E and F all calculate the same value by row. Column G fails with a #VALUE. In row 1 the value of angle[1] = 0 therefore column D = C = B = sin(0) = 0. In row 2 angle[2] = 1 therefore B = C = D = 0.017452
How can I get the user defined function sindeg(value) in column G to accept the named range variable 'angle' like the Excel function radians(value) accepted it in column D?
This functionality should work horizontally as well as vertically. For example enter 'angle' A1 to CM1 then have sindeg(angle) filled from A2 to CM2. It should also work in the case where the named range 'angle' is a single cell.
I am sure that this is a simple variable type definition problem in my user defined function: should the input variable be defined as type Range? Or something more exotic?
The brute force approach is to have the function determine the input value by passing in the named range, working out dimensions, calculating offset between the cell the function is in and top (left) of named range, then counting down (right) to pick the correct value. However I cannot see adding all that code to EVERY function. Occam's Razor says there has to be an easier way since Excel built in functions seem to do it readily.
View 8 Replies
View Related
Apr 4, 2008
I have a cell B10 which contains a formula.
I would like a macro which copies this formula across the same row.
However, the macro should prompt the user to select a range.
Based on the range selected and in particular the columns in this selected range, I would like the macro to copy the formula only for the columns specified in the selected range.
View 9 Replies
View Related
Mar 31, 2014
So I have 2 sheets from a much larger worksheet where I wish for the first sheet to extract a row of values, one at a time from the second sheet using a range of numbers I enter as reference for where to look for the data. Sheet 1 can be thought of as a summary page and Sheet 2 is where data is stored.
I need to first check if any data under Sheet 2 column B fall within a specified range of numbers and if any of those numbers are found I want it to grab the largest and latest number from that range and pull all the data from certain columns in that same row and place it into Sheet 1, one column value at a time.
Sheet 1 A1 = A range of numbers as text. 10-15, 16-20 etc Only one range is entered. This also tells me what results I'm looking at.
Sheet 1 B4:B14 = Destination cells for the individual data I'm wanting to pull from Sheet 2 columns H:P. B4 wants H, B5 wants I, B6 wants J etc
Sheet 2 column A = A3:A102 are numbered 1:100.
Sheet 2 column B = A series of numbers anywhere from 10-70. Always in sequence and they can repeat. 10,10,11,12,13,14,15,15,15,16 etc. Ranges from B3:B102. Only one number per cell.
Sheet 2 columns H:P = Data in H3:P102 I want to extract to Sheet 1 B4:B14.
Now lets say I want a formula for Sheet 1 B4 which wants a value in Sheet 2 H. If Sheet 1 A1 = 10-15, I want to check whether Sheet 2 column B has any values equaling those and then tell me which row that last number appeared in.
Example: Sheet 2 B4=14, Sheet 2 B5=14, Sheet 2 B6=16. Use B5. (B6 is outside range and B4 isn't the last time the 14 appears.)
Then, knowing B5 is the value I want, find which row it is in (row 5 in this example) or use the number in A5 (3) and then find my way to column H (H5) where the value I want to pull is.
Example 2: Sheet 2 B4=14, Sheet 2 B5=14, Sheet 2 B6=16. Use B5.
Sheet 2 H4=10, Sheet 2 H5=32, Sheet 2 H6=42. Place "32" from H5 into Sheet 1 B4.
I'd like to also have some error control so I'm not trying to pull data from blank cells if it's relevant. Maybe check if Sheet 2 X3=0 and if it is, do nothing as no data appears if the cell is 0.
I have put a lot of time into trying to solve this myself but I feel way out of my depth. I've tried going step by step but I can't seem to figure out which functions are relevant and also things like how to return the range that the A1 values appear in or if using MAX, not having it return values outside of A1's range also.
View 7 Replies
View Related
Oct 9, 2012
Trying to convert an Excel 2003 macro to work in Excel 2007.
The problem line is
Dim MyDataObject As DataObject
I suspect the problem is a Missing Reference, but I cannot figure out which one. I have the same ones (in 2007) as 2003 except for one which is not showing
Microsoft Forms 2.0 Object Library
Is this the one it needs? It is called something else in 2007?
The ones I do have ticked are
Visual Basic For Applications
Microsoft Excel 12.0 Object Library
OLE Automation
Microsoft Office 12.0 Object Library
Microsoft ADO Ext. 2.8 for DDL and Security
Microsoft DAO 3.6 Object Library
Microsoft ActiveX Data Objects 2.8 Library
Microsoft Scripting Runtime
Microsoft XML v2.6
View 8 Replies
View Related
Jul 29, 2014
I am using Microsoft Excel 2010 and Microsoft VBA 7.0 on my system. I would like to eventually create a PowerPoint and insert charts generated in the Excel workbook. In the meantime, I cannot get the basic PowerPoint created.
The line in red is highlighted blue when the compile error "User-defined type not defined" message box appears.
Public Sub TryAgain() Dim myPowerPoint As PowerPoint.Application
'
' do nothing for now
'End Sub
I have set the references such that Microsoft Project 14.0 Object Library is indeed checked. The Excel file only contains this code in a module. All sheets are blank. Nothing else is written yet.
View 1 Replies
View Related
Apr 12, 2009
My question is about creating User-Defined Data Types. Is there ANY way possible i can create a User-Defined Data Type that declares a variable of another User-Defined Data Type instead of the Pre-Defined User Types like String, Integer, etc?
The following explains my problem in more detail.
I know to create a User-Defined Data Type at the top of the module before any procedures. Like this:
View 6 Replies
View Related
Nov 28, 2006
I had a working subroutine which I moved to another workbook (rather than linking to it and having both workbooks open at the same time).
Now I get "user-defined type not defined" when it runs. Here is the beginning of the
Global oApp As Object
Sub UpdateForecasts()
Call Update1
Call Update2
End Sub
Sub Update1()
Dim dPath As String
Dim dDest As String
Dim dCondition As String
Dim dName As String
Dim FSO As New FileSystemObject
View 9 Replies
View Related
Jun 23, 2006
I can create my own new collection which is handy as it accepts uniques only and i can access using its "key"
But can i have a collection of "user defined data types"
View 5 Replies
View Related
May 5, 2013
Base 64 Encoding.
Dim objXML As MSXML2.DOMDocument
Dim objNode As MSXML2.IXMLDOMElement
Are causing the User Defined error, but the same workbook is OK in XP and Win 7.
VB6: Free, Easy and Quick Base64 Encoding and Decoding in Visual Basic [a NonHostile article]
Says you need a reference to Microsoft XML, v2.6 (or later) and the Win8/2010 workbook does have one for Microsoft XML, v6.0
View 1 Replies
View Related
Mar 4, 2010
I am trying to capture with Worksheet Change a command bar action like paste but I am getting an error :
“User-Defined type not defined”
Do I need a library of sort in References ??
Public Sub Right_Click()
Dim oControl As CommandBarControl
For Each oControl In CommandBars("Cell").Controls
Debug.Print oControl.Caption
If oControl.Caption = "&Paste" Then
oControl.OnAction = "MyPaste"
End If
Next oControl
End Sub
View 9 Replies
View Related
Oct 17, 2007
I have an array with structure, i.e. User Defined Type. Assume the user defined type has two elements: Element1 and Element2 and array name is Array.
So the definition is:
Dim Array(1 To 10) As UserType
and access to elements is
Array(5).Element1
The problem is that I need to pass the whole set of Element1 or Element2 to a function. Should it have been two separate arrays, it would not be a problem. But because of the user defined structure I have no idea how to pass a single element.
I hope there is another solution rather than to use loops. I have many arrays like this with complex structures. I simply can not replicate all of them.
View 9 Replies
View Related
Jun 27, 2008
When I try to complile my VBA project, I get the following error "User-defined type not defined" but the compiler doesn't point to any line.
I remember what I did last was to rename a form and a Module, but I replaced their old names in all my code with the new ones ... Does this have anything to do with the error I am getting ?
View 9 Replies
View Related
Oct 7, 2012
I have a financial dataset which I need to "clean" before manipulating/analysing.
Each row of the data represents a completed transaction and the first step is to delete rows that are done with particular (internal) clients; the client data (the client's name) is in Column D.
Currently, I delete the unwanted data by autofilter and delete (code below), however this means the clients to be deleted are only defined within the code. I would prefer to have a worksheet within the workbook where the user defines the clients by adding or subtracting their name from a list.
I have created a dynamic range for the client list by inserting a Named variable along the lines of "=OFFSET(!$B$3,1,0,COUNTA($B$3:$B$200)-1," which works fine.
However how do I work this list into my code so that it works when new clients are added or deleted?
Current code for deleting unwanted client data:
Sub filterdelete()
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.Rows.Count
With Range(Range("D1"), Range("D" & LastRow))
[Code] .....
View 2 Replies
View Related
Mar 25, 2008
I want to create a user defined function to search a column of data for a part number.
If it exists I want to have a the UDf returna "fail" otherwise "pass"
Here is the code I was trying to use
Function firstpass(SN As String) As String
ws = Worksheets("Defects")
c = ""
With ws.Range("a1:a9999")
Set c = .Find(SN, LookIn:=xlValues, lookat:=xlWhole)
End With
If Not c Is Nothing Then
firstpass = "Pass"
Else
firstpass = "Fail"
End If
End Function
This function only returns a "#value" and I don't quite know how to troubleshoot it.
View 9 Replies
View Related
Dec 11, 2012
Which I am trying to modify to fit my needs:
Code:
Sub Test()
Const cURL = "Website Here" 'Enter the web address here
Const cUsername = "XXXXXX" 'Enter your user name here
Const cPassword = "XXXXXX" 'Enter your Password here
Dim IE As InternetExplorer
Dim doc As HTMLDocument
Dim LoginForm As HTMLFormElement
[Code] .......
I get the error User Defined type not defined on line:
Code:
Dim IE As InternetExplorer
Do I need to use references? Is there a quick fix for this?
I have code that works for a particular website but I am having trouble making it work for others. This code seems more flexible than the other code:
Code:
Option Explicit
Public Sub Press_Button()
'make sure you add references to Microsoft Internet Controls (shdocvw.dll) and
'Microsoft HTML object Library.
'Code will NOT run otherwise.
[Code] ........
My end goal is to log on to several websites and pull data out of tables on the websites back into excel so that I can have a one stop shop instead of logging into many websites manually.
View 5 Replies
View Related
Aug 28, 2008
This code works fine when I use it, but not when a co-worker uses it on his PC. The code and VBA references are the same. He gets the "User-Defined Type not defined" error. I'm wondering if there is an Outlook setting that may blow this up.
the code was working on his PC and then it stopped though no changes were made to the code. That's why I think it may be blocked by an Outlook setting.
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
MailOutLook.Subject = "E-mail"
View 9 Replies
View Related
Sep 16, 2006
I've made a macro that inserts an entire new row above a specified cell, then updates each column of that row using offset.value and various constants and inputbox variables. Works great so far, unless I try to apply a validation rule to one of the cells.
The code I'm using to add the validation works okay when referring to a specific cell by reference e.g:
With Range("A1").Validation
etc...
However, when I change it thusly:
With Sheet2.Range("LastRow").Offset(-1, 5).Validation
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Departments"
.IgnoreBlank = True
.InCellDropdown = True
End With
It doesn't like that one bit.
This is part of a private Sub attached to a button in the same sheet. I've had a scan through the archives looking for validation threads, but couldn't find anything that refers to problems with offsets (if indeed that is the problem here).
View 9 Replies
View Related
Oct 4, 2006
Trying to add a named range at run-time
Here's what I have so far ...
View 9 Replies
View Related
Jun 9, 2009
I am having some trouble with a variable range selection within a regression. I keep getting an "application-defined or object-defined error." I've isolated each statement to find that the code that is causing the regression not to work is below (the error for that line of code states that the Select method of Range class failed):
View 6 Replies
View Related
Feb 26, 2009
this is the line it gives the error on.
Range("A1").End(xlDown).Offset(1,0).Select
View 9 Replies
View Related
Jun 5, 2009
So I'm correcting macro at work and keep running into this error:
"Application-defined or object-defined error"
View 5 Replies
View Related
Mar 14, 2014
In Sheet2 I have list:
columnA (name)
ColumnB (region)
Audi
Euro
Ford
USA
Chevi
USA
VW
EURO
Porshe
EURO
I used manager name to define range:
Cust_Name = Sheet2!$A:$A
Reg_Name = Sheet2!$B:$B
Now, in Sheet1 I did data validation and I have:
A2 = list of name (from Sheet2, columnA)
B2 = list of region (from Sheet2, columnB)
How to do, like if I in A2 I will choose Audi or Porshe then automatically in B2 will show Euro?
View 1 Replies
View Related
Jul 8, 2009
I'm having trouble getting a User Defined formula to work. I received an email containing a User Defined formula for SUMCOLOR and COUNTCOLOR. The first sums all the values in like-colored cells, and the second counts all the cells of like-color in a given range. The VB code for the module is as follows:
View 2 Replies
View Related
Jan 2, 2007
Possibility of creating "on measure" functions for the necessities of every customer, but I have some things to ask in merit and I hope that you can answer to me:
- which are the differences between a User Defined Function and a Macro?
- also User Defined Function is written in Visual Basic?
View 9 Replies
View Related
Jan 21, 2007
Can you create user-defined events in excel? I ask because the worksheet_change event does not capture pastes or undo/redo.
View 4 Replies
View Related
Oct 30, 2008
My problem is in this defined range in "C30,D30,E30, F30 & G30" there is a possibility of more than one entry. If that is the case the entry would be in "C31,D31,E31, F31 & G31" If this is the case I need to pick the later which is "E31, F31 & G31" not
"C30,D30,E30, F30 & G30". How can I do that?
View 8 Replies
View Related
Feb 2, 2009
I need to sum all the rows, except the header row, of a column inputted by the user. The column will be located in a worksheet dubbed SourceSheet.
Here's a few pieces of code related to what I am trying to do. The header row is always row 1. So the rows I'm summing are always 2 - myrows.
View 6 Replies
View Related