+ Reply to Thread
Results 1 to 14 of 14

Shifting data based on values

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Shifting data based on values

    Hello. Whenever there is 0 in B3 AND there is a value greater than 0 in C3, I would like to adjust the following data one column to the left. C3:K3, N3:V3, Y3:AG3, AI3:AR3. All of the other data will not adjust.

    Spreadsheet attached BUT it is just one row. In the real data I have 16,000 rows. Thank you!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Shifting data based on values

    Are you wanting EACH row to be evaluated individually? or if B3 = and C3 < 0 then shift everything, the ENTIRE dataset to the right?


    This evaluate and will shift each row individually:
    macro help With Code.xlsm

    Code with comments so you can understand what I am doing and why:
    Please Login or Register  to view this content.
    Last edited by mikeTRON; 09-02-2014 at 08:43 PM.
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Shifting data based on values

    This does that:
    Please Login or Register  to view this content.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Shifting data based on values

    Here's my attempt:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  5. #5
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Shifting data based on values

    @MikeTron: Yes, each row should be evaluated individually. Thanks everyone, I'll try these out.
    Last edited by ammartino44; 09-03-2014 at 12:55 PM.

  6. #6
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Shifting data based on values

    @ MikeTron. Your setup is a little different than mine. For example, in columns M:V, there would be 0's in columns M and data in columns N and O. The code works fine though. Thank you. Another question: When I run your data, it eliminates data from K, how could I make this all 0's? The point is to push the data back one year (given the criteria) but then this would make year 10, "0", because there is no data in that year. Does that make sense?

    Also, why do you clear contents in column K?
    What is cutcopymode?

    Thanks for your help!!

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Shifting data based on values

    Correction to my code for putting 0 in year 10.

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Shifting data based on values

    @ JBeaucaire. Could you add notes for your code? There were some things I didn't quite understand. Thanks for your help.

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Shifting data based on values

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Shifting data based on values

    @jbeaucaire. Beautiful, thanks. Just one more question: When you enter the "with" code, why do you set everything to ".value"?

  11. #11
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Shifting data based on values

    @trebor76. Thanks for your help. Would you mind writing notes with your code?

    A couple of question: 1) Why do you use a "const", is that necessary? 2) Why do you look for the last row in a different manner than jbeaucaire? Which way is better?

  12. #12
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Shifting data based on values

    The "." connects the commands to follow to the original WITH parent. Instead of having to identify parents over and over, then issue commands:

    Please Login or Register  to view this content.
    ...you can set a parent object once... makes editing easier:
    Please Login or Register  to view this content.

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Shifting data based on values

    Trebor's LR construct is fundamentally better as it looks for the "last used row" in several columns.

    Me, I prefer to select one key most important column, invariably column A, and just look UP that one column.

  14. #14
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,525

    Re: Shifting data based on values

    Hi ammartino44,

    Here's my code commented:

    Please Login or Register  to view this content.
    HTH

    Robert

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 0
    Last Post: 10-25-2011, 04:06 AM
  2. Replies: 3
    Last Post: 01-28-2010, 08:35 AM
  3. Replies: 8
    Last Post: 11-07-2009, 09:48 PM
  4. Shifting x-values in chart
    By Abed Alnaif in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-29-2008, 04:40 AM
  5. shifting values
    By ChinaBoat in forum Excel General
    Replies: 2
    Last Post: 06-23-2005, 09:54 PM

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