I am having trouble trying to coping the random generated data that I collected. I get Subscript out of range. I know what it from. But I can't seem to over come it. I have a userform with a textbox and 2 button. The first button creates a new worksheet called FW19 or what is entered in the textbox. The other button runs the random data gather and copy it to a sheet. But I am having trouble calling the new sheet and I get the script out of range. Code below.
VBA Code:
Option Explicit
Private Sub cmdBut1_Click()
Dim strFW As String
Dim LR As String
Dim ws As Worksheet
'' Creats Sheet name
strFW = UserForm1.txtbox1.Value
If strFW <> "" Then
Set ws = ThisWorkbook.Sheets.Add
End If
'' Creats txt in cells Al and B1
If strFW <> " " Then
ws.Name = strFW
Range("$B$1").Value = txtbox1.Value
Range("$A$1").Value = "Fiscal Week"
End If
End Sub
''Random Generator
Private Sub CmdBut2_Click()
Dim LastRow As Long
Dim NbRows As Long
Dim RowList()
Dim I As Long, J As Long, K As Long
Dim RowNb As Long
Sheets("INV_Data").Activate
LastRow = Range("A" & Rows.Count).End(xlUp).Row
NbRows = IIf(LastRow < 8000, LastRow * 0.003, 30)
ReDim RowList(1 To NbRows)
K = 1
For I = 1 To NbRows
RowNb = Rnd() * LastRow
For J = 1 To K
If (RowList(J) = RowNb) Then GoTo NextStep
Next J
RowList(K) = RowNb
'' below is the line I am having trouble with. When it gives me the erroe I hover
''over("strFW") and it shows me what ws it wants to copy to
Rows(RowNb).Copy Destination:=Sheets("strFW")(K + 2, "C")
K = K + 1
NextStep:
Next I
End Sub