+ Reply to Thread
Results 1 to 12 of 12

Adding specific value to numbers in a specific range

  1. #1
    Registered User
    Join Date
    06-16-2010
    Location
    Providence, RI
    MS-Off Ver
    Excel 2003
    Posts
    18

    Adding specific value to numbers in a specific range

    Hello
    I'm having some problem converting a large amount of data points, around 2000, to different values
    My company uses a measuring device to obtain specific thicknesses and we have to account for a variable that the device isn't able to account for.
    This leaves us with a large table of data that needs to altered to fit this range.
    Data that falls from 1-10 must have 3 added to it. Data ranging in 11-39 must have 6 added to them, and data that ranges over 40 must have 15 added to it.
    What would be a correct macro to swap over all this data? Please help. Thank you.
    Last edited by bmccarthy; 06-16-2010 at 04:50 PM.

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

    Re: Adding specific value to numbers in a specific range

    Like so perhaps?
    Please Login or Register  to view this content.

  3. #3
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Adding specific value to numbers in a specific range

    Based on my crystal ball (why don't you add an example to your post ?)

    Please Login or Register  to view this content.

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Adding specific value to numbers in a specific range

    Or, without VBa

    Assuming your data is in ColumnA begining A1

    In a spare column in Row 1
    Please Login or Register  to view this content.
    Fill/Drag down

    Copy

    Select A1
    PasteSpecial > values


    Hope this helps.

    If you need any further information, please feel free to ask further

    However

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.
    Last edited by Marcol; 06-16-2010 at 11:42 AM.

  5. #5
    Forum Contributor
    Join Date
    12-03-2009
    Location
    Providence RI
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    260

    Re: Adding specific value to numbers in a specific range

    Edit: I refreshed before posting this I swear lol.... butttt it didnt show any posts so others beat me to it.

    Adjust range as needed:

    Please Login or Register  to view this content.
    Last edited by Dulanic; 06-16-2010 at 11:38 AM. Reason: Edit: I got beat with same idea hehe.

  6. #6
    Registered User
    Join Date
    06-16-2010
    Location
    Providence, RI
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Adding specific value to numbers in a specific range

    thank you,
    the set of data will also be placed in a map, so the data is spread out throughout a large excel sheet, with bits and pieces here and there. will this operation mess up where the data is? It took forever to place the data where it is.
    Attached Images Attached Images

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Adding specific value to numbers in a specific range

    hmmm ....

    Why a picture?

    You would do best to post a sample workbook showing Before and After.

    It should clearly illustrate your problem and not contain any sensitive data.

    Cheers

  8. #8
    Registered User
    Join Date
    06-16-2010
    Location
    Providence, RI
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Adding specific value to numbers in a specific range

    I'm new at excel and trying to figure things out. i just wanted to show you that we have large areas that do not have data in them. are areas of work are 54x249 and the empty spaces need to remain empty. I ran snb's program and was getting empty areas filled "3" instead of remaing empty. this could easily be remedied in our scaling format though.

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Adding specific value to numbers in a specific range

    If you are new to VBa then this variation on Stephens' code should be a little easier to follow
    Please Login or Register  to view this content.

    This will ignore blanks or zeros and any text entries on your sheet. e.g. headers, and any descriptors you may have.

    Can you have negative values, and if so what are the rules that apply.
    (The code as it stands will do nothing with negative numbers)

    .....the set of data will also be placed in a map, so the data is spread out throughout a large excel sheet, with bits and pieces here and there. will this operation mess up where the data is? It took forever to place the data where it is.
    Test any code on a sample/copy sheet until you are happy with it.

    The code is not reversible (without a further macro), you cannot "Undo" VBa.

    Run it only once on the final data sheet

    You can of course save the workbook before running code, and if you are not happy with it, close the workbook without saving.


    Cheers
    Last edited by Marcol; 06-16-2010 at 01:06 PM. Reason: Select statement amended to allow for continuous decimal values

  10. #10
    Registered User
    Join Date
    06-16-2010
    Location
    Providence, RI
    MS-Off Ver
    Excel 2003
    Posts
    18

    Re: Adding specific value to numbers in a specific range

    Thank you everyone for your help.
    i was able to figure it out with this program

    Sub x()

    Dim r As Range

    For Each r In Range("a1:io52")
    Select Case r.Value
    Case Is <= 0: r = r
    Case 1 To 10: r = r + 3
    Case 11 To 39: r = r + 6
    Case Is >= 40: r = r + 15
    End Select
    Next r

    End Sub

    Thanks again

  11. #11
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Adding specific value to numbers in a specific range

    Your code will not cover all your values, eg 10.359 in column B:B, is this what you want?

    If not use the variation in post #9

    Also
    Please wrap your code in code tags, before the moderators get you...

    Forum rules
    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button.

    Cheers

    If you need any further information, please feel free to ask further

    However

    If this takes care of your needs, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED. It helps everybody!
    Also
    If you are satisfied by any members response to your problem please consider using the scales icon top right of thier post to show your appreciation.
    Last edited by Marcol; 06-16-2010 at 01:24 PM.

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

    Re: Adding specific value to numbers in a specific range

    If, as several here have suggested, you'd posted full details of your problem from the off, a tailored (and, frankly, a better than the one you arrived at, no offence) solution could have been provided from the off.

+ 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