+ Reply to Thread
Results 1 to 9 of 9

Mass way to modify number values

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    06-19-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    180

    Mass way to modify number values

    Hi

    I have a workbook with lots of analytic data from my company which I want to share with other people not associated with the company. Obviously I can't share private data so I'm wondering if theres a quick way to modify all the data I have with 'fake numbers' which means I could share it. With fake numbers no privacy rules will be breached etc.

    Is there a quick way to randomly change all numbers by +/- 10-20%?

    Thanks

  2. #2
    Valued Forum Contributor
    Join Date
    10-26-2008
    Location
    Birmingham, UK
    MS-Off Ver
    All versions up to 2010
    Posts
    1,025

    Re: Mass way to modify number values

    Hi
    You could use a formula like:
    =A1*1.2%
    Then copy it down your column.
    Then copy the column and use "Paste Special" to replace the formulae with just the values.
    This is assuming your data is already numbers of course :-).
    Hope this helps.
    Good luck.
    Tony

  3. #3
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Mass way to modify number values

    Select each sheet containing the numbers that you wish to adjust and run this small macro:

    Sub AdjustNumbers()
        Dim rAdjust As Range, r As Range
        Set rAdjust = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each r In rAdjust
            r.Value = r.Value * (100 + Application.WorksheetFunction.RandBetween(-20, 20)) / 100
        Next
    End Sub
    Gary's Student

  4. #4
    Forum Contributor
    Join Date
    06-19-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    180

    Re: Mass way to modify number values

    Quote Originally Posted by Jakobshavn View Post
    Select each sheet containing the numbers that you wish to adjust and run this small macro:

    Sub AdjustNumbers()
        Dim rAdjust As Range, r As Range
        Set rAdjust = ActiveSheet.UsedRange.Cells.SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each r In rAdjust
            r.Value = r.Value * (100 + Application.WorksheetFunction.RandBetween(-20, 20)) / 100
        Next
    End Sub
    Thanks, How do I modify this to select the data from cell J2 to cell N25730? I just want to plug in the code and play, thanks.

  5. #5
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,620

    Re: Mass way to modify number values

    Alternatively enter 1.2 in an empty cell and copy it
    Select all cells to be changed - Right click - Paste special - Multiply

  6. #6
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Mass way to modify number values

    Hi Pepe:

    I think the OP wants each original value to be multiplied by a random value between 0.8 and 1.2 rather than 1.2

  7. #7
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2504
    Posts
    13,620

    Re: Mass way to modify number values

    Quote Originally Posted by Jakobshavn View Post
    Hi Pepe:

    I think the OP wants each original value to be multiplied by a random value between 0.8 and 1.2 rather than 1.2
    Ah yes, thanks for pointing that out. I rest my case

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Mass way to modify number values

    Similar to Jakobshavn, however, using Evaluate to process by Area rather than Cell.

    Public Sub Example()
        Dim rngArea As Range
        On Error Resume Next
        For Each rngArea In Selection.SpecialCells(xlCellTypeConstants, xlNumbers).Areas
            With rngArea
                .Value = .Parent.Evaluate(.Address & "*(100+RANDBETWEEN(-20,20))/100")
            End With
        Next rngArea
    End Sub

  9. #9
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Mass way to modify number values

    Sub AdjustNumbers()
        Dim rAdjust As Range, r As Range
        Set rAdjust = Range("J2:N25730").SpecialCells(xlCellTypeConstants, xlNumbers)
        For Each r In rAdjust
            r.Value = r.Value * (100 + Application.WorksheetFunction.RandBetween(-20, 20)) / 100
        Next
    End Sub

+ 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