将列表框中的值粘贴到默认列(所选字段下的行)
Paste value from ListBox to default columns (row under selected field)
我尝试将 ListBox 中的值粘贴:总是在所选内容下方的一行中,粘贴到 C、D、E、F 列中。
我的代码:
Dim addme as Range
Set addme = Application.Selection
For x = 0 To Me.lbsourceList.ListCount - 1
If Me.lbsourceList.Selected(x) Then
'addme.Offset(1, ) = Me.lbsourceList.List(x, 1)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 2)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 3)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 4)'
Set addme = addme.Offset(1, 0)
End If
Next x
Offset (1,0) 会在下面一行,但我不知道如何将 C、D、E、F 列设置为默认值。
尝试下面的代码,让 Offset
工作 Selection
,但在 C 列。
Dim addme As Range
Set addme = Selection
' set the range to selection's row, but in Column C
Set addme = Cells(Selection.Row, "C")
' now offset 1 row below
addme.Offset(1) = "test offset"
编辑 1:更新代码以适应 PO 的新数据:
Range(Cells(addme.Row, "C"), Cells(addme.Row, "C")).Offset(1).Value = Me.lbsourceList.List(x, 1)
Range(Cells(addme.Row, "D"), Cells(addme.Row, "D")).Offset(1).Value = Me.lbsourceList.List(x, 2)
Range(Cells(addme.Row, "E"), Cells(addme.Row, "E")).Offset(1).Value = Me.lbsourceList.List(x, 3)
Range(Cells(addme.Row, "F"), Cells(addme.Row, "F")).Offset(1).Value = Me.lbsourceList.List(x, 4)
我尝试将 ListBox 中的值粘贴:总是在所选内容下方的一行中,粘贴到 C、D、E、F 列中。
我的代码:
Dim addme as Range
Set addme = Application.Selection
For x = 0 To Me.lbsourceList.ListCount - 1
If Me.lbsourceList.Selected(x) Then
'addme.Offset(1, ) = Me.lbsourceList.List(x, 1)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 2)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 3)'
'addme.Offset(1, ) = Me.lbsourceList.List(x, 4)'
Set addme = addme.Offset(1, 0)
End If
Next x
Offset (1,0) 会在下面一行,但我不知道如何将 C、D、E、F 列设置为默认值。
尝试下面的代码,让 Offset
工作 Selection
,但在 C 列。
Dim addme As Range
Set addme = Selection
' set the range to selection's row, but in Column C
Set addme = Cells(Selection.Row, "C")
' now offset 1 row below
addme.Offset(1) = "test offset"
编辑 1:更新代码以适应 PO 的新数据:
Range(Cells(addme.Row, "C"), Cells(addme.Row, "C")).Offset(1).Value = Me.lbsourceList.List(x, 1)
Range(Cells(addme.Row, "D"), Cells(addme.Row, "D")).Offset(1).Value = Me.lbsourceList.List(x, 2)
Range(Cells(addme.Row, "E"), Cells(addme.Row, "E")).Offset(1).Value = Me.lbsourceList.List(x, 3)
Range(Cells(addme.Row, "F"), Cells(addme.Row, "F")).Offset(1).Value = Me.lbsourceList.List(x, 4)