Consulting

Results 1 to 7 of 7

Thread: Write selected items on form to range

  1. #1
    VBAX Regular
    Joined
    Dec 2009
    Posts
    22
    Location

    Write selected items on form to range

    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!

  2. #2
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    try this
    ws.Range("A527:C544").ClearContents

  3. #3
    VBAX Mentor 大灰狼1976's Avatar
    Joined
    Dec 2018
    Location
    SuZhou China
    Posts
    479
    Location
    Hi HV_L!
    Try this
    ws.Range("A527:A" & ws.Range("A527").End(xlDown).Row).ClearContents

  4. #4
    VBAX Regular
    Joined
    Dec 2009
    Posts
    22
    Location
    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.
    Attached Files Attached Files

  5. #5
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    Try amendment
    With ws
    .range("A527:C544").ClearContents
    End with

  6. #6
    VBAX Regular
    Joined
    Dec 2009
    Posts
    22
    Location
    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

  7. #7
    VBAX Mentor
    Joined
    Apr 2009
    Location
    Kingsbury
    Posts
    423
    Location
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •