PDA

View Full Version : Write selected items on form to range



HV_L
05-30-2019, 02:04 AM
Hi,
I have a userform where multiple selections are checked.
I need to write that selected items to another sheet, and first emty the values in that range
I tried this:

ws.Range("A527:A544" & ws.Range("A527").End(xlDown).Row).ClearContents
But this gives error

Below this range is more, so cannot clear everything downwards
Actually the range is this much rows, but also the column C (where financial values are written manually) needs to get emptied. (Column B is not used so can be in the range)
How can I do this?

Thanks!

Rob342
05-30-2019, 03:50 AM
try this



ws.Range("A527:C544").ClearContents

大灰狼1976
05-30-2019, 03:54 AM
Hi HV_L!
Try this

ws.Range("A527:A" & ws.Range("A527").End(xlDown).Row).ClearContents

HV_L
05-30-2019, 04:27 AM
Hi,
Thnx for your time and reply.
Still not going well, now I see that if there are i.e. 5 values, then I select just one new value, the content is not cleared, just one row is affected, while I thought the range would get cleared..
Let me attach what I have, maybe that helps.

Rob342
05-30-2019, 04:51 AM
Try amendment


With ws
.range("A527:C544").ClearContents
End with

HV_L
05-30-2019, 05:08 AM
Not sure where to put this code..
Is this what you mean?

Private Sub Cmd_invoeg_Click()
With ws
.Range("A527:C544").ClearContents
End With
With LB_select
r = 0
For i = 0 To .ListCount - 1
If .Selected(i) Then
ws.Cells(r + 10, 1).Value = .List(i)
r = r + 1
End If
Next i
End With
LB_select.List = [kosten_tbl].Value
End Sub

Rob342
05-30-2019, 05:22 AM
as below you need to dim ws


Private Sub Cmd_invoeg_Click()
Dim ws As Worksheet
Set ws = Worksheets("Data")
With ws
.Range("A527:C544").ClearContents
End With
With LB_select
r = 0
For i = 0 To .ListCount - 1
If .Selected(i) Then
ws.Cells(r + 10, 1).Value = .List(i)
r = r + 1
End If
Next i
End With
LB_select.List = [kosten_tbl].Value
End Sub