+ Reply to Thread
Results 1 to 10 of 10

recalculating values across non continuous ranges

  1. #1
    Registered User
    Join Date
    11-09-2015
    Location
    us
    MS-Off Ver
    2007
    Posts
    7

    recalculating values across non continuous ranges

    Hello Excel Forum!

    Looking for some advice. I've got a macro enabled spreadsheet that is some 2100 rows tall with a 7 line repeating pattern starting at E2. It looks like this:

    Daily regular order product A -25
    Daily custom order product A -13
    Daily regular order product B -500
    Daily custom order product B -1000
    New stock product A
    New stock product B
    Total usage -1538

    How can I program VBA so that whenever an entry is made in rows 1 through 4 of the pattern, they are automatically converted to negative? For example, if i make an entry on row 989, that is row 1 in the pattern and should be changed to negative, but an entry on 986 through 988 should not be converted. Also, simply formatting as negative is not sufficient. The values on all seven rows are used elsewhere.

    The data on the sheet is archived and wiped each month, so I don't think an ordinary formula would work. Any ideas?

    Thanks,
    David

  2. #2
    Forum Contributor Obsessed's Avatar
    Join Date
    05-22-2013
    Location
    Cincinnati, Ohio
    MS-Off Ver
    Excel 365
    Posts
    215

    Re: recalculating values across non continuous ranges

    Why not just use data validation to force a negative number on these rows? What column is the text entered in? how many lines are there, or can there be?
    Want to show appreciation for the help you received from a member? Give them reps by clicking the bottom left of their post!

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: recalculating values across non continuous ranges

    Hello dvault101,

    Welcome to the Forum!

    To help you with this problem, you should post your workbook. We need to see how the data is arranged, what formulas you are using, etc.

    Please provide before and after examples of your data along with any notes you would like to include.

    If your workbook contains any sensitive information, please redact that information before you post.

    How To Post Your Workbook
    1. At the bottom right of the Reply window, Click the button Go Advanced
    2. At the top of the Your Message Window, in the first row of icons, Click the Paperclip icon.
    3. Click the Add Files button at the top right in the dialog box. This displays the File Manager dialog.
    4. Click the Select Files button at the bottom middle of the dialog.
    5. In the new window Find the file you want to upload, select it, and Click Open.
    6. You will now be back in the File Manager dialog. Click the bottom Middle button Upload File.
    7. Wait until the file has completely uploaded before you exit the File Manager dialog.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    11-09-2015
    Location
    us
    MS-Off Ver
    2007
    Posts
    7

    Re: recalculating values across non continuous ranges

    I've attached the worksheet. Other than summing each day's activity on row 7 of the pattern and a grand total on the right side, there is not much happening here. I would think I'd be on the right track with code like this, but i'm getting a type mismatch error on my IF line.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: recalculating values across non continuous ranges

    So in your example sheet if you want to change the number that was inputted to a negative version of that number and you are interested in columns F to AB and only those rows where it begins with Daily in column E, then try this.

    If I missed something let me know.

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: recalculating values across non continuous ranges

    I forgot to disable events.

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    11-09-2015
    Location
    us
    MS-Off Ver
    2007
    Posts
    7

    Re: recalculating values across non continuous ranges

    Perfect. Thank you!

  8. #8
    Registered User
    Join Date
    11-09-2015
    Location
    us
    MS-Off Ver
    2007
    Posts
    7

    Re: recalculating values across non continuous ranges

    Well, sadly i counted my chicken before he was fully hatched. Can definitely see a beak and a head though

    For the first group, it works flawlessly. I enter a number and if it is supposed to, it converts to a negative and everything's good. In the other rows, i'm getting unexpected behavior.

    Take cell N11. If I enter say 5 in that cell, I see that excel is changing the number to negative (good) but also changing the format from general to date (not good). It is also changing rows 6 and 7 in the pattern to date formatting as well. From what i see in the code, i'm only telling it to change the value, so what could be causing this?

    Also, once a value is entered for a cell in the range, you cannot clear the cell unless you've selected multiple cells. I don't want this to fire when deleting (eg a user enters a value in the wrong cell).

  9. #9
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: recalculating values across non continuous ranges

    Take cell N11. If I enter say 5 in that cell, I see that excel is changing the number to negative (good) but also changing the format from general to date (not good). It is also changing rows 6 and 7 in the pattern to date formatting as well. From what i see in the code, i'm only telling it to change the value, so what could be causing this?
    I'm using this code on your sample. I see no such behavior. I change N11 and the format after entering 5 is general. N6 and N7 remain empty and their format is also general.

    You need to post the sheet with the issues so I can check it out.
    This code should fix the deleting problem.
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    11-09-2015
    Location
    us
    MS-Off Ver
    2007
    Posts
    7

    Re: recalculating values across non continuous ranges

    Thank you Skywriter.

    The fact that the behavior did not duplicate for you helped me narrow down the problem. Somewhere in my "personal codebook" was a script that was also firing and causing the issue. I stripped it out and the code is behaving perfectly in all the rows and cells. Thanks!

+ 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. CountA in non-continuous cell ranges - data type mismatch
    By lifeseeker1019 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-30-2014, 06:45 PM
  2. Dynamic Named Ranges Not Recalculating
    By Ozan Ertem in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-09-2013, 01:36 PM
  3. Copy not continuous ranges and paste it new word file
    By suny100 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-26-2012, 02:16 PM
  4. Replies: 0
    Last Post: 02-20-2012, 05:42 PM
  5. User input from non-continuous ranges
    By vbanoob2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2011, 01:36 PM
  6. Counting Continuous Days within overlapping Date Ranges
    By mgaworecki in forum Excel General
    Replies: 3
    Last Post: 09-07-2011, 08:33 AM
  7. XY Scatter Chart non-continuous date ranges
    By dafydd_brown in forum Excel General
    Replies: 5
    Last Post: 05-14-2010, 04:17 AM

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