2017-01-11 27 views
1

我試圖從列表框粘貼值:alwyas一個行之下的選擇,進入塔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 

偏移量(1,0)將在下面一行下,但我不知道如何設置列C,D,E,F爲defualt。

回答

1

嘗試下面的代碼,以獲得SelectionOffset工作,但在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) 
+0

什麼II需要將其他值粘貼到列D,列E等旁邊......我需要設置一些附加值? – 4est

+0

此代碼將回復您的帖子,如果您想了解更多信息,請更新您的帖子 –

+0

歡迎您:) –