Loop through columns and take the highest value


I currently have 12 columns, so I want to loop through each column, take the highest value from the previous columns, and apply it to the current column.

For example, if column 1 > column 2 then column 2 = column 1 else no change. I want the same to apply for column 3, 4 and so on.

I want to be able to achieve this with loops, if possible.

Any suggestions will be high appreciated.

Thank you.

As it stands, its hard for me to envision what you’re trying to accomplish. You start out by talking about columns, then switch to individual rows in each column, then you switch back to columns.

It’s also unclear to me whether you want this comparison to happen between all columns, or just in order from 1 to 12, or pairwise.

I think it would be best if you provided some example data as well as an example of your desired output.

1 Like


So on my input, I have a random amount of figures for 12 months, but on my output, I want the highest running value.

Please see attached for a sample.

Sample of Data.xlsx (8.2 KB)


Seemed like one of those coding problems online.
Does this help?
max previous value.knwf (25.7 KB)



This is perfect.

Thank you so much.

1 Like

You’re welcome.
In case you have multiple rows.
max previous value.knwf (36.8 KB)


Thanks again.

This works perfect as well.

Much appreciated.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.