Formula Dependent On Variable Range
Aug 9, 2007
I've developed a code to load csv files in excel and do some formatting on it. In addition I want to add a few cells which calculate making use of the data in the file. The data tabel (resulting after the csv import) always has the same number of columns, but the number of rows varies depending on the imported file.
My problem now is that I need to change the formula for my calculation depending on this number of rows.
This is what I got so far (not including the csv import):
Option Explicit
Dim varRow As Double
Function fctCountNrRows() As Double
Range("A1").End(xlDown).Select
varRow = Selection.Row
End Function
Sub subAddTotals()
fctCountNrRows
Cells(varRow + 2, 1).Select ..............
View 9 Replies
ADVERTISEMENT
Sep 4, 2013
I have this table as my simple little database and I have to extract some info from it and keep track of dates and deadlines...
A
B
C
D
E
F
G
H
[Code]...
I have to get the following data, I need to lookup the last visit date out of all dates associated with a specific name in column "A".
This requires that I test an unsorted table for a value in column "A", i.e. "test2". Then determine which record has the latest date.
In other words, If I test for the value "test2" in column "A", I find I have 2 records, with dates ranged across "D4:F4 and D7:F7".
I need to return the latest date found in those ranges...
The purpose here is to write a function that will find a range of dates associated with a name in an unsorted table, from that range find the latest date, then add 90 days to that date and display the results....
I have been trying to employ a form of, =VLOOKUP(E3,$B$3:$D$11,MATCH($F$1,$B$1:$D$1,0),FALSE) and =INDEX(Table_Array,MATCH(Lookup_Value,Lookup_Array,0),Col_Index_Num) combined with "IF" functions, but to be totally honest I am COMPLETELY lost here....

View 9 Replies
View Related
Jan 27, 2014
how to make make cell D4 dependent on the value in cell D3. So if cell D3 = 10 (it's max), then cell D4 could equal 0-10. I want to use this in conjunction with Solver so that D4 is a variable, but can't be greater than zero until D3 is maxed out. I've already tried different formulas, but I'm not very good at writing them and data validation didn't seem to work either.
View 2 Replies
View Related
Jan 17, 2012
I am trying place the "sum" formula into multiple cells, changing with "i" (itteration process).
Something like:
.Range(17,counter).formula = "=Sum(B2:B20)"
when the couter itterates, the same line of code should give:
.Range(17,counter).formula = "=Sum(F2:F20)"
My actual code looks like: ... which doesnt work.
.Offset(17, " & ColumnHeadCout & " + 1).FormulaR18C" & ColumnHeadCout + 1 & " = ""=SUM(R[20]C[" & ColumnHeadCout + 1 & "]:R[" & NumberStreamElem + 20 & "]C[" & ColumnHeadCout + 1 & "])"
View 9 Replies
View Related
Nov 25, 2009
I have a custom data entry form which is working fine. The form completes customer data for reviewing at a later date. I have now been asked to change it so it will seperate the data in to customer's who require some documents sent out and some that dont.
Is it possible to have a combobox on the form and if the options on the combobox are Yes and No (original), when either option is selected the data will complete on to a seperate sheet for cases with documents required or documents not required?
View 4 Replies
View Related
Jul 6, 2007
I have below code (option 1) I was hoping would do what I need except instead of copying formula from A1 it copies values... (option 2) copies formula but does not preserve references...any ideas how to copy exact formula so that references are not changed?
Assumptions:
A1 formula = SUM(B2:E2)
in A5 I would like to copy exact formula to keep references to row 2...
I agree I could use $ in original formula but that would complicate other requirements.
OPTION1:________________
Sub test_var_object()
Dim vRange1 As Range
Set vRange1 = Range("A1")
Range("A5") = vRange1
End Sub
OPTION2:________________
Sub test_var_object()
Dim vRange1 As Range
Set vRange1 = Range("A1")
vRange1.Copy
Range("A5").PasteSpecial
End Sub
View 9 Replies
View Related
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
Nov 27, 2007
It is useful to use lookup function to find the student name. However, if the table array size is variable
(say, a new student enrolled and the table array will be $A$2:$B$7), the table array size will be changed
and we need to change the vlookup function. How to avoid it? Can we use some kind of variable for the
See attached file( book1)
View 9 Replies
View Related
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
Aug 3, 2006
The problem lies in the following line
Range(Cells(1, a), Cells(b, a)).Formula = _
"=(rc[-1]-" & min & ")/(" & max & "-" & min & ") "
When it is executed i get the 1004 error ("application-defined or object-defined error)...
min and max are defined (as worksheetfunction.min and max of a selection), and their values are correct. The problem seems to lie in the max variable, namely if i simplify the formula to just
Range(Cells(1, a), Cells(b, a)).Formula = "=(rc[-1]-" & min & ")"
it works ok, but if it is
Range(Cells(1, a), Cells(b, a)).Formula = "=(rc[-1]-" & max & ")"
I get the error.
I am completely baffled considering both variables are defined in the same way i.e.
min = Application.WorksheetFunction.min(Selection)
max = Application.WorksheetFunction.max(Selection)
View 9 Replies
View Related
Oct 8, 2007
Here is what I would like to do: Have a formula like Max(B12:B14) change to Max(B12:B18) when I change the value in different cell from 3 to 7. I would like to stay away from the macro world and keep in formula world if that is possible.
View 6 Replies
View Related
Dec 3, 2013
Code:
=SUMPRODUCT(--(_NamedRng1=NamedRng2),$B$49:$F$49)
I am using the above formula in my code with two Named Ranges
Code:
Set Rng3 = Range("_NamedRng1").Offset(1, 0)
=SUMPRODUCT(--(_NamedRng1=NamedRng2),rng3)
[/CODE]
I want to set the range $B$49:$F$49 in my code and I have tried the above, but it does not work.
I want to allow for the fact my end user may insert rows so do not want to use $B$49:$F$49
View 2 Replies
View Related
Jan 22, 2010
Situation:
I have two drop down lists 1) Country and 2) States/province
Country has list: [US, Canada]
If "US" is selected, [Arizona ,Florida, NewYork] is listed in the 2nd drop down list
If "Canada" is selected, [Alberta, Ontario, Quebec] is listed in the 2nd drop down list
Scenario:
First, I select "US" and choose the states to "Florida"
Next I change the country to "Canada" and forgot to choose province
Then, the 2nd dropdown list is changed to [Alberta, Ontario, Quebec],
BUT the current value is still "Florida"
Probem:
Now I have "Canada" and "Florida" selected in the sheet
Question:
If the primary list is changed, can I make the 2nd drop down list to show a default value (e.g. blank or the first entry i.e. Alberta)?
View 11 Replies
View Related
Apr 15, 2014
In the attached spreadsheet, I have data pertaining to the amount of money raised for a bunch private equity funds, and the dates when this money was raised.
For a little background, private equity funds raise money in various batches or "closes", so a fund may initially raise $5M in its "first close" and then in its "second close" it may raise another $5M or so. And then a "final close" would be the last time that fund would raise money.
I'm trying to figure out a way to move data in my "Fund Size" and "Fund Size Date" columns to the corresponding "First/Second/Final" close amount/date columns, according to the "Status" of the fund in my Column A.
Essentially, if a fund is either "Fundraising" or "Fundraising and Investing" status, then I would need the fund sizes and fund size dates to populate in the corresponding columns left to right.
And then if a fund is in "Investing" status, the most recent values (or those furthest right) would need to appear in the "Final Close" columns.
Fund Closes.xlsx‎
View 5 Replies
View Related
Aug 8, 2006
All to occur in cell G2
Condition 1.
If F2 is > 0 then multiply F2 by D2.
Condition 2 in the same cell.
If the product of F2 multiplied by D2 is > E2 AND the sum of F2 and F1
multiplied by D2 is > 0, then add the product of D2 multiplied by the sum of
F1 and F2 to E2, otherwise input E2
Condition 3 in the same cell.
If the product of F2 multiplied D2 is < E2 BUT the sum of F2 and F1
multiplied by D2 is > 0, then input the product of D2 multiplied by the sum
of F1 and F2.
Condition 4 in the same cell.
If F2 < 0, and the sum of sum of F2 and F1 multiplied by D2 is < 0, then 0.
This is the best way I could think of the write out my intention. I think if
I can get the above scenario into a one cell formula that should resolve my
pain.
View 11 Replies
View Related
Sep 6, 2006
I want to create a formula, the formula has to be dynamical.
e.g.:
A1 holds the nr - 5
A2 holds the nr - 8
Depending a solution of a sum, my answer is 1 or 2. This nr (1 or 2) is located in cel B1.
In cel D1 i want to have the numer 5 or 8 depending the previous answer. I want to use a code like this: A($B1), if B1 = 1 than cel D1 formula would be A(1) and has the value 5.
View 8 Replies
View Related
Nov 10, 2006
Say you define a public range variable called Inputworksheet and you set it to refer to the worksheet called Inputworksheet. You have a separate string variable with the value Inputworksheet. How do you get this string variable value to call/control the range variable Inputworksheet?
I am getting an excel worksheet value from a lookup function that corresponds to the name of a VBA range variable. Once I have this worksheet value, I would like to use the range variable that has the same name as the worksheet value.
View 5 Replies
View Related
Oct 30, 2013
I have the following table with weeks to display for the holidays and my column H has a drop down list of the first column in the table below with the Named Range, "SNCODE.Season_Codes".
The other two Named Ranges are, "SNCODE.Season_Codes.Start" and "SNCODE.Season_Codes.End"
I need my column K to display a list of weeks from the first week to the last week. For example, the cell in column K for Valentine's Day should have 1, 2, 3, 4.
Basic 1 53
Promotional 1 53
Seasonal Spring 1 13
Seasonal Summer 10 26
Seasonal Fall 23 39
Seasonal Winter 36 53
Valentine's Day 1 4
Halloween 31 40
Christmas 36 48
View 6 Replies
View Related
Oct 7, 2009
I have a datatable which has a column containing up to 25 different text codes (which are currency pairs). I need to insert a specific number (as seen in the attached example) in a second column. This number depends on the text in the first column. I suspect this is very simple but at the moment, not for me!
View 3 Replies
View Related
Apr 19, 2013
I have data that resembles (I have also attached an example workbook as well if that is easier)
Column A.................Column B................Column C..................Column D.............Column E................Column F
Year.......................Quarter...................Month..................Product-Code...........[data A]................[data B]
2013.........................Q1.........................Jan........................SD-21...................13%......................0.05%
2013.........................Q2..........................Apr........................NV-12...................7%.......................6%
etc
I am hoping to have, on another sheet, a series of dependent drop boxes- Year, Quarter, Month, SKU- which after selecting then displays 'dataA' & 'dataB'.
So you could select- List 1: 2013 ----> List 2: Q1 ----> List 3: Jan ----> SD-21.................and then 13% and 0.05% are displayed.
The data will be continuously added to and so needs to be based on a dynamic data range.
I know that a pivot table is the perfect way to do this, however my bosses have requested that I do not use that format so it is easy for all staff to access.
So I think I need to construct some sort of dashboard sheet, I have experimented with OFFSET from other posts, but so far have had no joy.
View 14 Replies
View Related
Apr 4, 2008
I am trying to autofill dynamic ranges that have column variables (d) and row variables (x)... I am having a hard time with the syntax on this
View 9 Replies
View Related
May 12, 2014
I have three columns that each have a drop down of text options; column A has three options, column B has three options and column C has two options. I want to have a fourth column that will show a text value dependent on the combination of the three columns.
It ends up being 18 variations so my IF formula just won't compute.
This is basically the format I have and works for a few values then just chucks up an error when I extend it to all 18 variations:
IF(AND(A1="text",B1="text2",C1="text3"),"show this text",
IF(AND(B1="other",B1="other2",C1="other3"),"then show this", ) etc etc
Any way I can get this to work for all 18 possible outcomes??
View 6 Replies
View Related
Mar 11, 2008
I am using a variable named " Totals" as a range type to refference the range in a formula. It works the way I have it.
Dim Totals As Range
Set Totals = [U37: AE37]
Now instead of the absolute refference, I would like to change the row refference by an offset of my current row, using a formula with a varriable. The columns stay the same.
View 3 Replies
View Related
Feb 19, 2010
I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.
The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?
View 6 Replies
View Related
Jan 27, 2012
I am trying to write code to select a range in a worksheet where the last cell in the range is variable.
Sub DataTest()
Dim LastColumn As Integer
Dim LastRow As Long
Dim LastCell As range
[Code].....
View 8 Replies
View Related
Jan 25, 2013
I have a named range, called SubjectNamesPastoral on a worksheet called Worksheets("Group to Teacher")
I can't assign the named range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable in vba.
the first two lines of code work fine, the msgbox shows "E100:E105", happy days!
However when I try to assign the same range to the rngSubjectFamilyRangeOnSubjectUsedSheet variable, the debugger runs past the 'Set' line without error, but throws 'error 91' at the second msgbox.
VB:
thisString = "SubjectNames" & strSubjectFamilyOfGroup
MsgBox Range(thisString).Address
Set rngSubjectFamilyRangeOnSubjectUsedSheet = Worksheets("Group to Teacher").Range(thisString)
View 1 Replies
View Related
Jul 16, 2009
I am using the code below to copy a range and paste it over a variable range.
View 4 Replies
View Related
Mar 6, 2008
I have been working on part of the code for my spreadsheet and it works fine in the spreadsheet “Databaseform” however when I copied the code to my master spreadsheet “Paul_PartLocDBCombo” it does not work, I get the error:
Method ‘ range’ of object ‘_worksheet’ failed
The code is then highlighted in yellow, the code is:
Set rng = wksPartsData.Range("a1", Range("a65536").End(xlUp))
Meaning this part is incorrect but I don’t know why? To work it: go to Databaseform and press start. Enter 7mm in the product field and press find all. It will then return all the matching results in the userform. Its this I want to try and achieve on the other spreadsheet when the button find label is pressed.
View 3 Replies
View Related
Oct 25, 2007
I have a range "C1:Cx" where i want x to be the value from a value "overallLastRow". How do I write this?
View 9 Replies
View Related
Oct 26, 2008
This is just a simple question but I can't seem to find the answer in any of the hepl files. I want to refer to a range by using a variable but can't get the syntax right.
for example instead of
View 2 Replies
View Related