Results 1 to 6 of 6

Finding Max of multiple cells and assigning the value to a variable

Threaded View

  1. #1
    Registered User
    Join Date
    11-15-2009
    Location
    ~1 AU from the Sun
    MS-Off Ver
    Excel 2007
    Posts
    5

    Finding Max of multiple cells and assigning the value to a variable

    Hello!

    I have experience writing Macros for Excel, but I cannot seem to figure out how to perform an operation. I hope that someone here will be more familiar with the syntax and passing of parameters to help.

    I have two nonadjacent columns; C and F. I would like to find the maximum of two cells in the same row and assign the value to another cell (same row) in J; up to a certain row.

    For example:

    ____C____ F____ J
    1|__0____ 5____ 5
    2|__10___ 9____ 10
    3|__1____Null___1
    4|__Null__63____63

    What I have so far is something along the lines of:

    Sub Max()
    Dim rownum
    rownum = 1 'starting row position
    Do While rownum <= 4 'final operation taking place at row 4
         Range("J" & rownum).Value = Max(Range("C" & rownum).Value,Range("F" & rownum).Value) 'trying to assign the max value of two cells to a third cell
         rownum = rownum + 1 'incrementing row number by one to proceed to next rowLoop
    End Sub
    I could do this with a few IF statements, but my goal is to do it in a single line. I don't see why it couldn't be done. I just think my syntax for passing the Value parameter to the Max function is incorrect. Nor do I believe that I am calling the Max function properly.

    *The reason for not simply typing in a formula into the cells as "=Max(C1,F1)" is because I have around 500 rows of data, not every single row has data, i.e. C and F may both be Null, and I will be using this to perform another function to assign a different value to J later on.
    Last edited by DonkeyOte; 11-16-2009 at 04:22 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1