Defining Variable Range In Sumif Function With VBA Within Table

Jul 28, 2014

I sum number of articles that are coming in on one sheet and articles going out on another. The total of In - Out is a separate value. All three values are placed on a third sheet.

The following code I use does the job, but I have to use a set range in the SumIf function. I want to be able to use a variable for the lastrow of a table colum.

VB:
Private Sub ArttotKnop_Click()

Dim Klanttel As Integer
Dim Rij, vLastRow, iLastRow As Long
Dim varResult, varMin, varTotal As Variant

iLastRow = Sheets("Ingebracht").ListObjects("Ingebracht").ListRows.Count
[Code] ....

Since my table grows larger every day I want to use variables.

Where I wrote A2:A500, B2:B500, B2:B550 and D2:D550 I want to be able to replace A500 and B500 with A and B + the variable iLastRow. The same for B550 and D550 with the vLastRow variable

Tried using:
.Range("A2:A" & iLastRow)
.Range("A2", Cells(iLastRow, 1))
.Range(Cells(2, 1), Cells(iLastRow, 1))

They don't work.

View 2 Replies


ADVERTISEMENT

Defining A Range With Variables And Cells Function

Aug 25, 2009

I am trying to make the "A4:A" portion of this line of code generic so it can work in multiple different files. I have defined a variable FirstGridRow that will take care of the '4' but I need to find a way to splice it all together. Essentially I am stuck trying to tack on the ":A". The first piece shows where I am coming from and the second is where I am trying to go to.

View 3 Replies View Related

Formula- To Pull Cell Values Similar To A SUMIF Function (SUMIF(range,criteria,sum_range))

Oct 25, 2007

I am trying to pull cell values similar to a SUMIF function (SUMIF(range,criteria,sum_range)). For example, in A1 I use a data list created from data elsewhere on the spreadsheet. In the data I created elsewhere, there are 2 columns being used. The 1st column is the information that is being used to create the list and the second column contains specific values (number or text). In the dropdown menu I select an available value (text or number) . When I have selected that value I would like cell A2 to show what the cell directly to the right of it shows from the data I have elsewhere in the spreadsheet as mentioned. I have tried the SUMIF function however it seems to exclude certain values (number or text) and I am not sure what else to use.

View 9 Replies View Related

Adding Variable To Specific Sheetname In A Sumif Function

Feb 4, 2010

Hi, looking for help desperately in fine tuning a formula. I have a formula at the moment (which works) for searching through a list on a separate file and totalling up all values which relate to it, see below:

=sumif([filename.xls]1’!$B:$B,D10,’[filename.xls]1’!$H:$H)

The tab ‘1’ in the formula relates to the first of the month so this month there are 28 different tabs with similar information.

With C10 containing the date in this instance, does anybody know a way of making ‘1’ a variable so that entering ‘04/02/10’ would change it automatically into a 4? (Unfortunately for me changing the 1 to =c10 didn’t work).

View 14 Replies View Related

Sumif Several Sheets And Using A Variable Criteria Range

Oct 23, 2008

Currently I’m using several formulas to acquire my result; I know it can be abbreviated to a more compact formula.

I have four Sheets. One summary sheet and SheetA, SheetB and SheetC containing Data.
All sheets are documented in an equal format, e.g.: in column A: Date, column B: Code (A, B, C or D) and Column C: values.

Criteria are located in the summary sheet e.g.: A2: 1-1-2008 A3: 2-1-2008 and B2: A, B3:B
The data sheets are listed in H1:H3.

The results should cover a sum of col C over the sheets by using the critiria listed in summary sheet.

The criteria range is variable; sometimes I only want to use one criteria and sometimes more.

View 9 Replies View Related

Defining A Variable As New Collection

Dec 7, 2008

I have a piece of code I am using to important data from a text file. The code works fine but I am having a hard time understanding how defining a Variable "As New Collection" works. I have tried to research on numerous websites dedicated to excel but had no luck finding any further information.

I have executed the code line-by-line over-and-over and believe what the "new collection" does is it creates some type of external database that is hidden within excel (that's just my guess). I have attached a sample file and a text file with dummy data if needed to see how the code is working.

View 4 Replies View Related

Making / Defining Workbook As Variable In VBA Macro?

May 7, 2014

In my VBA macro, it copies data from this.workbook, and paste to another "destination" workbook. That destination workbook must be opened first before the macro is run.

Within the Macro code, I had to specify the exact name of the workbook which the data is pasted to.

The problem is that the exact name of that workbook which it paste to changes every week.

Is there any method where my macro can be changed and updated with the name of the destination workbook each week without manually opening and editing the code. The user of this.workbook is not technical enough to edit and maintain the macro each week

View 8 Replies View Related

Defining Variable Data Row For Chart Series

Oct 5, 2006

I want the below code to run from R1C10 (i.e. cell J1) to the end of the data in the row, which will vary in position, rather than having to define where the end of the row will be beforehand (i.e. R1C21).

Is this possible?

View 9 Replies View Related

How To Use Date Range In SUMIF Function

Dec 22, 2013

I am trying to use a date range as a criteria in a SUMIF function. Below are the data and formula I am using.

Forecast
6
4
15
8
Week
1/12/2014
1/19/2014
1/26/2014
2/2/2014

Formula =SUMIF(G2:J2,">L1",G1:J1)

G1:J2 - raw data shown above. L1 = 2/2/2014. Desired result = 8. Result obtained with formula above = 0 how to make this work?

View 3 Replies View Related

SUMIF Function But The Sun Range Is On The Left Side Of The Criteria?

Aug 19, 2014

I am trying to SUM the total task done per date. The problem is, (for the sake of this problem) the DATE is in Column B and the Task Total is in Column A. I know that SUMIF is not possible because the SUM RANGE should be always on the right side of the CRITERIA.

My question is, is there other formula other than SUM IF to figure this out? or I have no choice but to Interchange the data in a matter that SUMIF function will run.

View 6 Replies View Related

Code That Inserts A SUMIF Function To A Given Range Of Cells

Dec 10, 2008

I'm trying to write some code that inserts a SUMIF function to a given range of cells:

In simplified form, the code runs as follows: ...

View 9 Replies View Related

SUMIF Function: Sum A Range Of Cells Greater Than Whatever Is In Cell D8

Jul 18, 2006

I am trying to use the SUMIF function in excel where I want to sum a range of cells greater than whatever is in cell D8. Here is what I tried to use, but it doesn't work. SUMIF(A2:A10,>D8,B2:B10)

The content in D8 can change because the user makes a choice from the drop-down list and a number pops up in D8 that is referenced to their choice.

View 2 Replies View Related

Combined VLOOKUP With A Date Range SUMIF From Pivot Table Data?

Feb 13, 2014

I have a report I am attempting to populate with data from a pivot table in another worksheet. Column A holds all the reference numbers (primary key), column B contains various start dates, and I want column C to contain all the payments made since the start date for each reference number.

The source data is a pivot table with Row = Reference number, column = transaction date, values = transaction amounts. This is an extremely large table, as I'm processing data from almost 1,200 cases, which each have around 20 payments spread over the last year, on completely random days. What I would like to do is build a formula in my report which looks up the records for the reference number from column A, and then adds up all the payments which have been made after the date in column B (and ignore any payments in the table which are before that date).

And to make things more complicated:

if an error is generated, it needs to return as 0, not #N/AThe report has the dates in UK format dd/mm/yyyy, but the pivot table has the dates in SQL format: yyyy-mm-ddThe pivot table is connected to a SQL database via ODBC and has to refresh every time it is opened.

=IF(ISERROR(VLOOKUP(A2,'Transactions'!$A$2:$B$1194,2,FALSE)),0,VLOOKUP(A2,'Transactions'!$A$2:$B$1194,2,FALSE))

View 5 Replies View Related

MAX Function With A Variable Range

May 29, 2014

MAX function with a variable range. I want find the highest value in a changeable range in a column. The problem for me is, how can I automatically change the range where the highest value is returned.

Here is an example:

Cell A1: 14

In cell A1 is the number entered that specifies the range. In this example the range is 14 rows =MAX(A18:A31).

A2 126.36
A3 126.16
A4 124.93
A5 126.09
A6 126.82
A7 126.48

[Code] .....

Using =MAX(A18:A31) returns 128.57. So far so fine.

But what is the MAX function if the range value refers to the number entered in cell A1? If I change the value in A1 from 14 to 20 how can I make the MAX function flexible that it refers to cell A1 as the range value?

Using the value 20 in cell A1 the MAX function would be =MAX(A12:A31). I can change this manually of course but I want a MAX function that refers to cell A1 as the range value.

I want also mention that the data series is update every day, so that each day a new value is added in column A, e.g. A32, A33, A34. and so on.

View 13 Replies View Related

Sum Function Using Variable Range

Feb 17, 2014

I would very much like to sum a range of values using variables instead of hardcoded ranges. I have tried the following (and variations of )

Range("D2").Formula = "=Sum(Cells(rowIndex1, colIndex1), Cells(rowIndex2, colIndex2))"

where rowIndex1 is starting row number, colIndex1 is the starting column number.....

It does not work.

View 6 Replies View Related

VBA Max Function For Variable Range

Jan 27, 2010

I need to calculate the max over a range of figures in a macro.

The "from" is a variable, call it X
The "to" is my counter in a loop so (Cells(-(Counter - 1), 5)

What I'm trying to do is to tell Excel that I want the max from X to the current counter cell.

e.g. Application.Max(Application.Index(X, 1):Cells(-(Counter - 1), 5))

but this gives me an error. I also attach a spreadsheet.

View 5 Replies View Related

Variable Sheet Name In Range Function

Aug 19, 2009

How should this read? So SheetName is the variable in the range funtion?

Dim SheetName As String
SheetName = ActiveSheet.Name

Set AllCells = Range('" & SheetName & "'!B7:'" & SheetName & "'!B60000")

View 9 Replies View Related

VBA CountA Function For Variable Range

Apr 22, 2006

I am trying to produce VBA code that will perform the CountA function on a variable number of lines in a column. My macro first sorts the worksheet by department number and then inserts 2 blank rows when there is a change in departments. Most departments have several rows of data, but some may have only 1. In column N of the first blank row following each department, I want to count the number of rows for that department.

View 3 Replies View Related

Variable Range In Function/Formula

Oct 3, 2007

I have an excel based report where I drop data into a blank spreadsheet each month and my formula (in a second worksheet) finds the relevant information. I do this by using the Match function on the first row of my source data. This finds the column numbers to the data I am interested in. (This is handy as additional columns of data appear almost every month). Most of my formula (in the second worksheet) works on vlookups using the column number from the match function.

However, I need to do a sumif. Sumif requires cell references rather than a column number. How can I get around this? Due to the nature of the report, VBA isn't appropriate in this instance. I'm only producing the initial report; someone else will be updating it each month.

View 2 Replies View Related

Variable Row Range For Formula / Function

Mar 12, 2008

How do I pass MATCH or COUNTIF the current dynamic row instead of hardcoding $3? The column is fine hardcoded. Column F has data validation allow List with source equal to dynamic range "userlocation". Column H has data validation allow List with source =OFFSET(userlocation,MATCH($F$3,userlocation,0)-1,1,COUNTIF(userlocation,$F$3),1)

In Column H, this will in effect provide me with a list of values based upon the value of cell F3. Problem is I can't seem to figure out how to reference ROW as a dynamic reference in my MATCH and COUNTIF function.

EX
Column F Column H
Screen1 (if Screen1 = value in my dynamic range pass me back value in a list)
Screen2 (if Screen2 etc.
Screen3

View 3 Replies View Related

IF Formula - Defining And Range

Jan 22, 2010

I would appreciate knowing how to fix this formula to do more than less than/more than answers. How do I have the following answers return for these birth year ranges? I have attached a sample file, with the formula in place. Thank you so much for any help!

1974-1991 = amateur 18-35
1900-1973 = amateur 36 and up
1992-1994 = junior 15-17
1995-2005 = junior 14 and under

blanks or zeros = unknown

View 8 Replies View Related

Defining Cell Or Range

Jun 11, 2009

I'm having an issue trying to locate a certain value in a cell.
If it is a number, say 50, then my code works, if its a word though
then it doesnt work. How can I get this to search with a list of words rather then numbers?

Sub alpha()
Dim cell As Range
For Each cell In Range("A2", ["N27"])
If cell.Value = Beff Then cell.Interior.ColorIndex = 6 'doesnt work
If cell.Value = 50 Then cell.Interior.ColorIndex = 6 'does work
Next cell
Range("A2", ["N27"]).Font.Bold = True
Range("A2").CurrentRegion.Copy
Sheets("Sheet1").Select
Range("A1").Select
ActiveSheet.Paste
Sheets("Sheet1").Select
End Sub

View 9 Replies View Related

Defining Average Range With Variables?

Apr 5, 2012

It's just meant to work through a long list of data blocks defined by column 8 changing. At that point I want to calculate the average of the first 20 entries in columns 12, 13, 14, 15, 16, 17 in that particular block.

I can achieve the sort and calculate the block start rows OK, just can't get the average definition right.

Code:
Option Base 1
Dim c(6)
Sub calc_averages()

[Code]....

View 2 Replies View Related

User Defining A Cell Range

Mar 31, 2014

I'm having some issues getting a tool I'm working on to function correctly. I have some cells, the number of which can vary based upon user requirement, that contain cell addresses. What I need from VBA is to translate these addresses into usable row, column values for the user defined range. Example:

Cell D4 contains F14, which was input by the user.

What is the best way to pass this data through VBA. Right now I am currently using:

Code:

Dim strRange as String 'left out loop parameters
dim TempRange as Range
strRange(i) = Cells(4, 4) 'using TypeName on StrRange at this point yields a string result as expected
set TempRange = Range(strRange(i))

From my understanding that should work but I am getting type mismatch.

I do not have any reason for actually using a string, but would like the user input to only be 1 cell. If there are cleaner ways around this, I am open to them.

Then from the range, I would have two other variables as type long for storing the row and column data using:

Code:

Pathing_Rows = TempRange.Row
Pathing_Cols = TempRange.Column

View 6 Replies View Related

VBA - Defining The Range Of Cells Containing Formulas

May 24, 2007

Using the SpecialCells method with a Type = "xlCellTypeFormulas", I can identify the range contains cells with formulas.

But when there isn't any of these cells in the range you've applied the SpecialCells method to, you get a VBA Error 1004. (Doing this outside VBA gives you a "No cells found" box.) How can I skip over this error?

I'm looping through each sheet in the workbook, and defining the UsedRange. I'm doing another loop that uses the HasFormula property on each cell and then performing an action if HasFormula = True, but this results in a lot of extra work processing cells that don't have formulas.

I'd like to further refine the process by defining the range of cells on each sheet that have formulas. But if a sheet contains no cells with formulas, I'd like to skip past it and move on.

I think this is just a simple syntax / code construction question.

View 9 Replies View Related

Defining Named Range, Error Criteria

Apr 13, 2007

I am trying to define a dynamic range based upon error criteria. After the first error, all the subsequent cells are filled with the error and I would like to limit the named range to the rows with no errors (one column wide). I am thinking something similar to (realizing this is probably very wrong):

=OFFSET( 'Basin Routing'!$X$5,0,0, COUNTIF('Basin Routing'!$X:$X,AND(NOT(ISBLANK()),NOT(ISERROR()))),1)

View 4 Replies View Related

SUMIF With More Than One Variable

Nov 17, 2006

creating a formula to sum up by more than one variable (org, grade, tickets). Please see the example below: ...

View 9 Replies View Related

Sumif With Variable Parameter?

Mar 6, 2014

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

Sumif With Variable In Cell

May 13, 2007

I have a large range which contains serial numbers (8 characters long) for a product and the quantity sold for each. Range is B2:C5000. Beside it on the worksheet I have the serial numbers for each product family (the first 4 characters of the serial number). Range is F2:F100. Now I'm trying to sum the quantity sold for each product family. I.E. trying to sum the quantities for the serial numbers in column B which contain the first 4 characters from column F

Here's what I tried: Sumif(B2:B5000, "*1234*",C2:C5000) This works but requires me to manually enter the serial numbers from column F (here I just randomly wrote 1234). Therefore, is there a way to take the Sumif and it the criteria part to tell it to look at the value in F2,F3,F4... and sum the quantities for the serial numbers which contain the value in that cell.

View 2 Replies View Related

SUMIF Function To A Particular Value

Apr 17, 2009

I am trying to used the sumIF function in refer to a particular value, e.g. Name 1.

Question 1 - What formula I can used to make sure the SUMIF function refers to that specific value, e.g Name 1?

Question 2 - Is my SUMIF function correct to calculate the SUM of hours to a Task? This is due to the data table setting? find attached:

View 3 Replies View Related







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