Change sheet name inside formula by changing static sheet value - excel-2007

=IF(ROWS(E$10:E10)<=$C$6,INDEX(Sheet4!B$2:B$200,SMALL(IF(Sheet4!$A$2:$A$200="Sprint-1",ROW(Sheet4!$B$2:$B$200)-ROW(Sheet4!$B$2)+1),ROWS(E$10:E10))),"")
This is my formula, i would like to change the static value "sheet4!" with my dynamic value which i will enter in cell "C4".

Indirect() will do it for you.
Your Current Reference
Sheet4!$A$2:$A$200
Change it as
=INDIRECT('"&C4&"'!$A$2:$A$200)
Like the above change rest of your references.
Caution:
Indirect() is a volatile function which recalculates on any change.

Related

VBA Excel - Update Cell value based on other cell value

I am trying to write a formula in a Range of cells based on other range cells values from another worksheet. The formula is shown below:
ActiveSheet.Range("G14:G43").Formula = "=Worksheets("1ºperíodo").Range("V14:V43").Value"
But the code doesn't work and I get a syntax error. That must be related with the strings but I don't know how to fix it.
The value at V14 must be equal to the value at G14 until the last cell, i.e., the value at G14 equals the value at V43. Besides the syntax error is the formula correct based on what I expect to have?
"=Worksheets("1ºperíodo").Range("V14:V43").Value"
is not a formula. It is a value.
If you only want the static values then just assign the values:
ActiveSheet.Range("G14:G43").Value = Worksheets("1ºperíodo").Range("V14:V43").Value
If you want a live formula you need to pull vba from the string and use the .Address function:
ActiveSheet.Range("G14:G43").Formula = "=" & Worksheets("1ºperíodo").Range("V14").Address(0,0,,1)
But the above can be simplified to:
ActiveSheet.Range("G14:G43").Formula = "='1ºperíodo'!V14"
With the formula, we only need to refer to the first cell with a relative reference and vba will make the changes to each row.

How to make dynamic cell in formula based on pointed value in excel spreadsheet

I have an issue with the cell range in formula and I don't know how to change it based on a predefined value in the spreadsheet. For example, from figure I have cells B8:B12=0 (5 cells), however, if I want to change range to range B10:B12=0 (3 cells) I should delete them from formula. How can I do the reference to a specific cell in a spreadsheet where I can simply change value 5 to 3 and it will change automatically, without interfering formula each time? I'm new to VBA, any help is appreciated.
As it was mentioned before, you should try offset function and do something like:
AND(SUM(OFFSET(D13,-1,-2,-(G6),1))=0). Then the cells in the range B8:B12 would be possible to change inserting range in cell G6.
Use the =INDIRECT function to define your target cells, e.g.
=TEXT(INDIRECT(A1), "")
If I entered the text B3 into cell A1, then this formula would return the text value in cell B3.
Let me know if it works for you.

finding a cell with variable data inside

This might be too easy for you but I can not find a solution.
I have a value in column O2 which has a variable number inside. I am trying to use the vlookup to see in which column i have the duplicate of the value inside of O2.
If the the value in O2 would be the same, then it would be easy to use vlookup. But the value inside of O2 varies as following.
O2= Company (variable value)is not defined
So how can i put this in a formula to be able to find matching cell with O2?
If you try to use value from a range in a VBA VLookup formula, try something like this:
With Activesheet
.Range("C1") = WorksheetFunction.VLookup(.Range("O2").value,.Range("A1:B10"),‌​1)
End with
The With Activesheet, couldbe changed to the sheet you need to use. If you are using only one sheet, try this:
Range("C1") = WorksheetFunction.VLookup(range("O2").value,range("A1:B10"),‌​1)

VBA Variable in range

Hey is it possible to use a variable within a range object?
My goal is to keep the formula that is in the excel cell, but the value of the cell itself is to be deleted.
The procedure for a better understanding:
1. search for a value, where "i" is indicating the row, where the value is found
2. delete this value, BUT: save the formula
3. another value is entered in this cell and the formula is still active and is checking some condition
Searching is no problem, but I cant delete the value of the cell without deleting the formula aswell.
This is what i tried:
rangeA = "D" & i
Set rConstants = Sheet1.range(rangeA).SpecialCells(xlCellTypeConstants)
rConstants.ClearContents
Any ideas?
You should set the constant equal to rangeA.Formula. You can then use the constant wherever you would like within your module or VBA project.

VBA Goalseek with Variable instead of Cell

I need to use Goalseek in my VBA code, but rather than seeking a goal for a target "CELL" in my spreadsheet, I need to seek a goal for a "VARIABLE" within my VBA code.
e.g.
Rather than setting some target CELL to "A3", I need to set a target VARIABLE declared in my VBA code.
Same applies, of course, to the "By changing" field.
Is that even possible?
Use a cell location that is off-screen to do the calculation, then once the process is finished, load the cell value into your variable, e.g.:
...GoalSeek ... ChangingCell:=Worksheets("Sheet1").Cells("A5000")
MyVar = Worksheets("Sheet1").Cells("A5000").Value