+ Reply to Thread
Results 1 to 7 of 7

Need macro to find max/min in rows and then manipulate the data

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72

    Need macro to find max/min in rows and then manipulate the data

    Hi there,

    I'm wondering if someone can help me do this in a macro:

    1. for rows 2 to the '$' symbol that it must find by itself (located in column A)

    2. search columns A to '&' symbol that it must find by itself (located in row 1)

    3. for the rows it finds from 2 to the $ sign, it looks to find the max and min value of each row

    4. it stores the max and min value

    5. it subtracts the min value of each row from each value of the row

    6. it divides each value of the row by the (max value of the row - min value of the row)





    eg of table.
    _______col1 col2 col3 col4 col5 col6
    row 1: Date Time Cash Car Other &
    row 2: 12 34 56 78 90
    row 3: 11 23 45 76 92
    row 4: $

    the program would only run from row 2 to 3 (before it finds '$' in col 1)
    the program would only run from col 1 to col 5 (before it finds '&' in row A)

    it would find for row 2: min = 12, max = 90, then it would subtract each value in row 2 by 12 and then divide all the entries by (90-12=78)
    to change row 2 to: 0 0.282 0.564 0.846 1

    it would find for row 3: min = 11, max = 92, then it would subtract each value in row 2 by 11 and then divide all the entries by (92-11=81)
    to change row 3 to: 0 0.148 0.420 0.802 1

  2. #2
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Need macro to find max/min in rows and then manipulate the data

    Please could you attach a workbook?

  3. #3
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Need macro to find max/min in rows and then manipulate the data

    The workbook is to be created by the user of the program

    They will be the ones copying and pasting different tables on the spreadsheet for the program to work with

    That is why the $ and & symbols are there. It is scale adjustment for the user depending on how many datasets they have.

    Since I was unable to do that, i had put an example of what it was to be at the bottom half of my original post.

  4. #4
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Need macro to find max/min in rows and then manipulate the data

    I have created an example

    It is slightly different but the idea remains the same.

    (see attached workbook)
    Attached Files Attached Files

  5. #5
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Need macro to find max/min in rows and then manipulate the data

    Try this:
    Sub x()
    
    Dim nCol As Long, nRow As Long, rng As Range, rng2 As Range
    
    nCol = Rows(1).Find(what:="&", after:=Range("A1"), Lookat:=xlWhole).Column - 1
    nRow = Columns(1).Find(what:="$", after:=Range("A1"), Lookat:=xlWhole).Row - 1
    
    Set rng = Range(Cells(2, 2), Cells(nRow, nCol))
    For Each rng2 In rng.Rows
        Cells(rng2.Row, 11) = WorksheetFunction.Min(rng2)
        Cells(rng2.Row, 12) = WorksheetFunction.Max(rng2)
        Cells(rng2.Row, 13) = Cells(rng2.Row, 12) - Cells(rng2.Row, 11)
        Cells(rng2.Row, 11).Copy
        rng2.PasteSpecial Operation:=xlSubtract
    Next rng2
    
    End Sub

  6. #6
    Registered User
    Join Date
    01-14-2009
    Location
    Toronto
    MS-Off Ver
    Excel 2003
    Posts
    72

    Re: Need macro to find max/min in rows and then manipulate the data

    that doesn't encorporate the:

    divide by (max - min) after the subtract does it?

  7. #7
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: Need macro to find max/min in rows and then manipulate the data

    In none of your posts have you once used the words "please" or "thank you" and after I provided you with that code all you can do is point out that I didn't do something which wasn't even in your attachment.

    So I don't really see why I should bother to help you any more.

+ Reply to Thread

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