Hi Nigel,
Thanks for your message regarding the above, and sorry for the delay in replying - I haven't been online here recently.
See if the following code does what you need:
Sub CreateArrayForUserForm()
Dim vColumnNo_Worksheet As Variant
Dim iColumnNo_Worksheet As Integer
Dim iColumnNo_Array As Integer
Dim vaUserFormData As Variant
Dim iLastRowNo As Integer
Dim iRowNo As Integer
Dim wks As Worksheet
iColumnNo_Array = 0
Set wks = ActiveSheet
With wks
iLastRowNo = .UsedRange.Rows(.UsedRange.Rows.Count).Row
' Specify the column numbers from which data should be copied
For Each vColumnNo_Worksheet In Array(1, 5, 10, 14)
iColumnNo_Worksheet = CInt(vColumnNo_Worksheet)
iColumnNo_Array = iColumnNo_Array + 1
If iColumnNo_Array = 1 Then
ReDim vaUserFormData(1 To iLastRowNo, 1 To iColumnNo_Array)
Else: ReDim Preserve vaUserFormData(1 To iLastRowNo, 1 To iColumnNo_Array)
End If
For iRowNo = 1 To iLastRowNo
vaUserFormData(iRowNo, iColumnNo_Array) = .Cells(iRowNo, iColumnNo_Worksheet).Value
Next iRowNo
Next vColumnNo_Worksheet
' Just to test the result, copy the array to the source worksheet - omit this from the final version
With .Range("T1")
Range(.Cells(1, 1), .Cells(iLastRowNo, iColumnNo_Array)).Value = vaUserFormData
End With
End With
End Sub
The highlighted code can be altered to suit your own requirements.
Hope this helps - as always, please let me know how you get on.
Regards,
Greg M
Bookmarks