Compare cell Values

Solved/Closed
Vba Beginner - Jul 14, 2009 at 06:07 AM
 ?????? - Sep 1, 2010 at 06:04 PM
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

venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
810
Jul 15, 2009 at 07:45 AM
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
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
0
mali naman yan
0
venkat1926
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
810
Feb 6, 2010 at 07:01 AM
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
-1