+ Reply to Thread
Results 1 to 9 of 9

shuffle names in cells, ignoring blank cells, macro

  1. #1
    Registered User
    Join Date
    05-14-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    shuffle names in cells, ignoring blank cells, macro

    Hello all,

    I have a macro assigned to a shape that shuffles names around that assigns the workers to a machine. Not all machines run so there are blank spaces. But when I use the macro, it shuffles the names around and it might move it to a machine that is not running. Here is my code:

    Sub ShuffleArrayInPlace(InArray() As Variant)
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' ShuffleArrayInPlace
    ' This shuffles InArray to random order, randomized in place.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim N As Long
    Dim Temp As Variant
    Dim J As Long

    Randomize
    For N = LBound(InArray) To UBound(InArray)
    J = CLng(((UBound(InArray) - N) * Rnd) + N)
    If N <> J Then
    Temp = InArray(N)
    InArray(N) = InArray(J)
    InArray(J) = Temp
    End If
    Next N
    End Sub


    Public Sub Afternoons()

    Dim x() As Variant

    x = Application.Transpose(Range("AF5:AF16"))
    ShuffleArrayInPlace x
    Range("AF5:aF16") = Application.Transpose(x)

    x = Application.Transpose(Range("AF18:AF23"))
    ShuffleArrayInPlace x
    Range("AF18:AF23") = Application.Transpose(x)


    End Sub

    This will shuffle the names in cells AF5 -AF16 & AF18-AF23. What code do I need to add to this so it will ignore blank spaces that maybe within those cells?

    thanks everyone.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: shuffle names in cells, ignoring blank cells, macro

    You would change your range reference to eliminate the cells for idle machines.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    05-14-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    Re: shuffle names in cells, ignoring blank cells, macro

    So you're suggesting to edit the Macro each time and remove any cells that are blank?

    if so, that wouldn't be the ideal way,

    It would be our supervisors on the floor using this file and some have little excel experience to go in and edit macros.

    i would think there has to be a code to "ignore blank" cells.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: shuffle names in cells, ignoring blank cells, macro

    The answer provided was based on your code as it exists. There is insufficient detail included in the post to gererate a different code.

  5. #5
    Registered User
    Join Date
    05-14-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    Re: shuffle names in cells, ignoring blank cells, macro

    Oh ok,

    To break it down, i have names in cells between say, A5 -A16. I may have A6 and A13 with no names in it. As of right now, with the code, it will shuffle all the cells from A5-A16 and maybe put the blank cells now at A8 and A10. I dont want that to happen. I want all the names to still shuffle, but for the cells at A6 and A13 to remain blank.

    The next day, i might have cells A7 and A9 blank, and want them to remain blank when i press the shuffle button. So i am hoping for a code to ignore blank cells when it does the shuffle as the blank cells maybe in a different location each day.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: shuffle names in cells, ignoring blank cells, macro

    This seems to work:

    Please Login or Register  to view this content.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  7. #7
    Registered User
    Join Date
    05-14-2018
    Location
    Canada
    MS-Off Ver
    2010
    Posts
    12

    Re: shuffle names in cells, ignoring blank cells, macro

    That seems to work perfectly! Don't understand what it means but it works :P

    thanks everyone!

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: shuffle names in cells, ignoring blank cells, macro

    You're welcome and thanks for the rep!

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: shuffle names in cells, ignoring blank cells, macro

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. 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. Replies: 3
    Last Post: 07-24-2017, 01:41 PM
  2. [SOLVED] Ignoring Blank Cells
    By prudential in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-16-2015, 11:21 AM
  3. Ignoring Blank Cells
    By tangmere.milli in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-11-2014, 07:02 AM
  4. [SOLVED] Rank string ignoring blank cells and o value cells
    By BRISBANEBOB in forum Excel General
    Replies: 3
    Last Post: 03-02-2014, 12:56 AM
  5. Replies: 5
    Last Post: 01-24-2013, 06:29 AM
  6. Excel 2007 : Ignoring Blank Cells
    By stellaselectxi in forum Excel General
    Replies: 4
    Last Post: 10-24-2010, 04:22 PM
  7. Ignoring cells with zero value or blank
    By Moshsoft in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-25-2009, 04:13 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