Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88030

Combining IF formulas in Excel with variable ranges [duplicate]

$
0
0

I'm a beginner here. I'm looking to essentially run formulas down in a separate column taking metrics from another column into the formula. Since each month of data is 4000 rows long, The range upon this formula will change from month to month.

The formula in Excel looks like this, and I want to replicate it in VBA with using variable ranges.

=IF(H15>=PERCENTILE($H$15:$H$628604, 0.95), H15, 0)

I came up with this:

Range(NewRangeU).Formula = "IF(" + NewRange2 + ")">=(PERCENTILE(" + NewRangeU + ", 0.95)"

I essentially don't know how to combine the two formulas in VBA.

NewRangeU = M4624:M9209
NewRange2 = M4624

So the formula in each cell going down the column should be:

=IF(M4624>=PERCENTILE($M$4624:$M$9209, 0.95), M4624, 0)

=IF(M4625>=PERCENTILE($M$4624:$M$9209, 0.95), M4625, 0)

 =IF(M4626>=PERCENTILE($M$4624:$M$9209, 0.95), M4626, 0)

and so forth.

I know how to add variable ranges inside VBA, what I don't know how to do is combine Variable Ranges with multiple Formulas that includes a condition. I haven't been able to find this answer from my search. The suggestion from the moderator on my original post didn't help with the question.

The suggestion doesn't work below.

Range(NewRangeU).Formula = "=IF("& NewRange2.Address(False, False) & ")">=(PERCENTILE("& NewRangeU.Address(False, False) & ", 0.95)"

I've also tried combining them into a string which also doesn't work.

String1 = "=IF(" + NewRange2 + ">="
String2 = "PERCENTILE(" + NewRangeU + ", 0.95)"
String3 = String1 & String2
'Range(NewRangeU).Formula = String3

Viewing all articles
Browse latest Browse all 88030

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>