shuffle names, ignoring blanks, macro

aikenhead

New Member
Joined
Apr 27, 2018
Messages
12
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:

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.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top