Please help to code has debug.

motilulla

Well-known Member
Joined
Feb 13, 2008
Messages
2,422
Office Version
  1. 2010
Using Excel 2010
Hello,

When I run code it stop at line below with error 438 does not RandomizeColumn

VBA Code:
.SortFields.Add2 Key:=rc.Offset(0, 1), SortOn:=xlSortOnValues, Order:=xlAscending

MrExcel Question.xlsm
ABCDEFGHIJKLMNOPQR
111.1931.4311.09701.6942.147002.3861.6941.0971.1451.4311.049
2X1.19301670692239097806928831.09701.002
3209551.1222.386002.3861.40800406144955335
42.3862.3862.3862.3862.3862.3862.3862.3862.3862.3862.3862.3862.3862.386
5CombiP1P2P3P4P5P6P7P8P9P10P11P12P13P14
6110,887
7210,987
8310,488
9410,275
10510,544
11610,717
12710,661
13810,546
14910,017
151010,925
161110,959
171210,025
181310,882
191410,477
201510,687
211610,372
221710,573
231810,935
241910,865
252010,906
262110,995
272210,481
282310,887
292410,793
302510,447
312610,253
322710,623
332810,73
342910,228
353010,279
363110,693
373210,884
383310,712
393410,886
403510,503
413610,203
423710,279
433810,504
443910,716
454010,05
464110,59
474210,895
484310,538
494410,064
504510,632
New Request Fill By Value
Cell Formulas
RangeFormula
D4:Q4D4=SUM(D1:D3)
E6:E50E6=RAND()


Code:
Sub FillByValue()
    Dim c As Integer
    Dim d As Integer
    Dim e As Integer
    Dim r As Range
    Dim sh As Worksheet
    Set sh = ThisWorkbook.Worksheets("New Request Fill By Value")
    
    With sh.Range("D6:Q3505")
        .ClearContents
        For Each r In .Rows(1).Cells
        c = 0
        d = 0
        e = 0

        If Cells(1, r.Column).Value > 0 Then
            c = Cells(1, r.Column).Value
            r.Resize(c).Value = Range("C1").Value
        End If
        If Cells(2, r.Column).Value > 0 Then
            d = Cells(2, r.Column).Value
            r.Offset(c).Resize(d).Value = Range("C2").Value
        End If
        If Cells(3, r.Column).Value > 0 Then
            e = Cells(3, r.Column).Value
            r.Offset(c + d).Resize(e).Value = Range("C3").Value
        End If
        RandomizeColumn r.Resize(c + d + e)
        Next r

    End With
End Sub

Sub RandomizeColumn(rc As Range)
    rc.Offset(0, 1).FormulaR1C1 = "=RAND()"
    With rc.Parent.Sort
        .SortFields.Clear
        .SortFields.Add2 Key:=rc.Offset(0, 1), SortOn:=xlSortOnValues, Order:=xlAscending
        .SetRange rc.Resize(, 2)
        .Header = xlNo
        .Orientation = xlTopToBottom
        .Apply
    End With
    rc.Offset(0, 1).ClearContents
End Sub

Regards,
Moti
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Use .Add not .Add2 which did not exist in 2010.
 
Upvote 1
Solution
I have one more question I have one formula which work under Excel 365, I want to use it with my excel 2010 post #1 in D6 and copied across to Q50. Is it convertible? If not please suggest one.
VBA Code:
=LET(a,REPT($C$1&" ",D1),b,REPT($C$2&" ",D2),c,REPT($C$3&" ",D3),SORTBY(TEXTSPLIT(TRIM(a&b&c),," "),RANDARRAY(D1+D2+D3)))
Regards,
Moti
 
Upvote 0
That is a completely different issue and should be posted as a different question please. (none of those functions have simple equivalents)
 
Upvote 0
That is a completely different issue and should be posted as a different question please. (none of those functions have simple equivalents)
RoryA, thank you for replay, perfect I will open new thread.

Have a nice day. Good Luck!

Best Regards,
Moti
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,403
Members
452,325
Latest member
BlahQz

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