Hi I require help in creating a loop procedure
My data starts from cell a5
The loop should start from cell b5, add values of b5 and c6, next add b5,c5,d5 to a different sheet until no of times I specify
This should happen until last used row in a5
Hi I require help in creating a loop procedure
My data starts from cell a5
The loop should start from cell b5, add values of b5 and c6, next add b5,c5,d5 to a different sheet until no of times I specify
This should happen until last used row in a5
Last edited by 6StringJazzer; 01-24-2019 at 01:44 PM.
Attach a file with sample data and a mockup of what you want the result to look like.
What is your level of expertise in VBA?
Hi,
Please check below
Capture.JPG
1) Loop needs to start from D2, Add values of B2 and C2, check if D2 value is more than average of sum of B2 and C2, if more highlight in red
2) Loop need to continue at E2 where it needs to add values of B2,C2,D2 and check average, if more highlight in red
3) Loop need to stop before grand total in row
Hi any help on this?
First I requested that you attach a file and you attached an image. We can't modify an image. The paper clip icon does not work for attachments. To attach a file, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.
Second, I asked about your level of expertise in VBA and you did not address that.
Is this a pivot table?
Hi,
Thanks for reply, attaching the file..
Yes, info provided is sample data, but my actual data is from a pivot table.
(i have copied pivot table contents to a different sheet through vba, if able to show info on actual pivot table that will be even helpful)
My knowledge on vba is moderate..
A couple of questions:
A) How does the logic for the USA row work? You have only highlighted the first 4, but those initial 0s should pull the cumulative average down to where all of the entries in the USA row are highlighted. Your logic is not clear to me.
B) Are you required to use VBA for this? It seems to me like it would be simpler to use conditional formatting with an appropriate formula. https://support.office.com/en-us/art...b-f1951ff89d7f In your sample spreadsheet I:
1) Selected F5:I10
2) Conditional formatting -> New Rule -> Use formula.
3) Formula is: =F5>AVERAGE($D5:E5) [note the mix of relative and absolute references] Format is: Red text.
That highlighted all the same values -- except for the USA row as mentioned above. Even if I am misunderstanding your desired logic, the same approach should work -- we just need to figure out exactly what formula logic you need.
I guess the big question at this point if if you are required to use VBA for this, or if you can use conditional formatting.
Originally Posted by shg
Hi MrShorty,
This info is from pivottable, assuming there are weeks in column I would like to start from week 3, where week 3 needs to sum values of week 1 and 2. If week 3 value is more average of week 1 and 2 then week 3 should be red
Continuing on week 4, this needs to add values from week1,2,3 and if week 4 is more than avg of these three week 4 should be red
Like this goes on till last column
This cannot be done with conditional formatting as my no of weeks might be 40 to 50,
If I understand, this is not what you have done in the USA row:This info is from pivottable, assuming there are weeks in column I would like to start from week 3, where week 3 needs to sum values of week 1 and 2. If week 3 value is more average of week 1 and 2 then week 3 should be red
Continuing on week 4, this needs to add values from week1,2,3 and if week 4 is more than avg of these three week 4 should be red
Like this goes on till last column
D column: average(0,0)=0 -> 4 is greater than 0 -> so text is red (which it is).
E column: average(0,0,4)=1.3 -> 3 is greater than 1.3 -> text should be red, but you have not marked this as red. Why?
F column: average(0,0,4,3)=1.75 -> 7 is greater than 1.75 -> text should be red, but you have not marked this as red. Why?
G column: average(0,0,4,3,7)=2.8 -> 8 is greater than 2.8 -> text should be red, but you have not marked this as red. Why?
Do you understand my confusion about the exact logic you are trying to use?
I don't understand why a variable number of weeks would prohibit you from using conditional formatting. You should just need to expand the selection and include appropriate conditions. I:
1) Selected F5:BD10 (assuming you would never need more than 52 weeks total)
2) Conditional formatting -> New Rule -> Use formula.
3) Formula is: =AND(F$4<>"Grand Total",F5>AVERAGE($D5:E5)) [note the mix of relative and absolute references] Format is: Red text.
Again, this highlights all of the same numbers -- except for the misunderstanding around the USA row.
I -- perhaps in error -- got the impression that it was copied from a pivot table but not trying to apply to the actual pivot table. That could change things.That was my first thought, which is why I asked about the pivot table. IME if your pivot table changes the number of rows and columns, it wipes out any conditional formatting that had been applied.
Edit: OP seems to have confirmed that he is trying to apply the formatting to a copy of the pivot table, not the actual pivot table.
As noted, I selected the entire 50 column block, so I did not need to do this for each column separately. A lot of times, if you pay careful attention to relative and absolute referencing, your formula/format can apply to the entire range. That is why I tried to draw attention to how I used relative and absolute references for this formula.
I'm not sure I understand what you mean by "loop formula". Are you saying you still want to see how this would be done in VBA?
Here is the link where there is no reply from that forum
https://www.mrexcel.com/forum/excel-...light=Vba+loop
Last edited by 6StringJazzer; 01-26-2019 at 09:42 AM.
We are all confused by your description of what you are trying to do. I have attached a file with two versions, one using VBA and one using conditional formatting.
Hi,
Thank you very much the vba part worked for me...
Hi @6StringJazzer,
The vba part is working,Thank you..
I would like to know is it possible in the above dataset to omit blank and zero in a row and then calculate average only for cells which has a number?
It seems like it should be as simple as replacing the AVERAGE() function with an AVERAGEIFS() function. Using my conditional formatting formula from post #10 as an example: =AND(F$4<>"Grand Total",F5>AVERAGEIFS($D5:E5,$D5:E5,">0")) Or am I misunderstanding something that makes it more difficult than an AVERAGEIFS() function?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks