Compare cell Values [Solved/Closed]

Report
-
 ?????? -
Hello,

i want to compare the Content of 2 Cells And Replace the value of the cell with the lowest value. like this

cell A1 got a value of 21 and Cell B1 got a value of 32

then i want cell B1 to stay as it is And Change The value of A1 for 21 to 32

any easy way to do this With VBA,? because im gonna use it in a Macro.

Thanks.

4 replies

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
796
try this macro and post feedback

Sub test()
Dim m As Double, n As Integer, p As Double
m = WorksheetFunction.Min(Range("a1"), Range("B1"))
n = WorksheetFunction.Match(m, Range("a1:B1"), 0)
p = WorksheetFunction.Max(Range("A1"), Range("B1"))
Cells(1, n) = p


End Sub
4
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 2942 users have said thank you to us this month

Hi,

I haven't tried the macro yet but i'm still struggling with it, however, I'm trying to compare the numeric occurance (results) of words in a list (Col C) identified using MS IF function, against the 'Control' list of numeric Instances of words (Col B)
i.e. Col A contains the words and Col B & C are the numeric occurances in both the Control and The Results respectively.
Esentially I think the IF formula would be, something like:
=IF(C4>=B4,"B4")(C4<B4,"C4")
So if the response in C4 is equal to or greater than the control B4, it returns the value of Cell B4
and
if the response in C4 is less than the 'control' B4, it returns the value of Cell B4
I don't think the IF function can be used to return the actual value of the Cell enclosed in the quote marks " " , which is a shame.

Any suggestions using this approach would be appreciated.

Best regards
mali naman yan
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
796
your logic is

=IF(C4>=B4,"B4")(C4<B4,"C4")
THIS IS NOT A MS EXCEL FORMULA
for this the formula is

=IF(C4>-B4,B4,C4)
There are only two alternatives

C4>=B4
C4<B4

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!