+ Reply to Thread
Results 1 to 13 of 13

Need code to rearrange select values

  1. #1
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Need code to rearrange select values

    Hoping some one can help me out with this find and replace code. I need a script that can find negative value in columns C thru H. The negatives then need to be totalled in column B and replaced with a "0" in there original location. Also values in column I have to be readjusted to correctly sum positive values in columns D thru H. attached is a sample file with orginal data in columns A-I and the desired output in columns M-U. Highlighted rows are the ones that would be adjusted by the script.


    Thanks in advance, s4
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need code to rearrange select values

    Hi
    The macro on this sheet does what you need.

    Enjoy.
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    It's very close. It still would need some minor adjustments to work the way I need it to. Sorry there is a couple things I should have been more clear about. In some cases there are positive values in columns D-H (like row 43 in the sample I attached), Column I needs to be revalued based on the sum of the positive numbers in columns D-H. Also column B has to sum the negatives in C-H, some cases there can be more than one negative value. Thanks, s4

  4. #4
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Need code to rearrange select values

    Ok.

    I have amended it as per your rquest.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    it still needs a minor tweak, in the case where there are multiple negative and positive values in the same row it doubles the value it places in columns B and I. I changed the sample file to show a couple scenarios where this occurs, see rows 38 & 40. appreciate all your efforts... s4
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need code to rearrange select values

    This is my interpretation.
    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    that works correctly, Is there a way to have it return in columns A-I versus off to the right? also any negatives in column C need to be replaced with a 0 and included in the sum in column B also. like the case in row 42.

    thanks, s4

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need code to rearrange select values

    Is this what you are asking?
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    Yes it is, that works perfefect, I just needed to make one minor change,

    .Offset(, .Columns.Count + 3).Value = a
    to
    .Offset(, .Columns.Count - 9).Value = a

    very nice, thanks again.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need code to rearrange select values

    You are welcome.

  11. #11
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    one other question, if I insert columns to the left , for example if columnsA & B are insert as row labels how would I need to modify the script?

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: Need code to rearrange select values

    If you insert col.A & B and the data/label is somehow connected to the original data range, the data range is now have 2 more columns.
    So you will need to adjust the col reference like
    Please Login or Register  to view this content.

  13. #13
    Forum Contributor
    Join Date
    09-12-2012
    Location
    Michigan
    MS-Off Ver
    Excel 2007
    Posts
    127

    Re: Need code to rearrange select values

    perfect! thanks again.

+ 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