Following code I've used allows the data from the Range of cells on a sheet:
Private Sub UserForm_Initialize()
listTo.Clear
listCC.Clear
listTo.List = Worksheets("Main").Range("C12:C26").Value
listCC.List = Worksheets("Main").Range("D12:D26").Value
End Sub
This works fine. Then my problem now is how to return them back to the sheet if the user clicks the Update
button. I've found some answer here, but I can't see any changes or seems to be not working. Below is my edited code:
Private Sub btnUpdate_Click()
Dim dataItems As Range
With Me.listTo
Dim Data()
ReDim Data(1 To .ListCount, 1 To 1)
Data = .List
With Worksheets("Main")
Set dataItems = .Range("C12", .Range("C12").Offset(Me.listTo.ListCount - 1, 0))
End With
With dataItems
.Value = Data
End With
End With
End Sub
This works only if I run the code from the first time, but if I re-run it, it's not working anymore. Any help?