2015-11-06 83 views
-6

我有兩張紙,其中第1張紙的L6將具有來自第2張紙B中範圍的數據:B。我需要一個宏,根據命令選擇B:B,然後將第一個單元格值(B1)複製到sheet1的L6,在下次單擊它時,應選擇B2並將值複製到L6,達到最後一個值或空白它應該顯示一個消息「沒有價值」。逐個複製範圍值

+0

下面是一些例子循環http://www.xlorate.com/excel-vba-loops.html – Davesexcel

+0

嗨Neelesh,你嘗試過anythng?如果是的話,請把代碼放在我們可以幫助改進:) – Linga

+0

感謝您的鏈接戴夫,但它並沒有幫助我什麼,我正在尋找。@ Linga我使用數據驗證列表截至目前。但從列表中選擇每一次都很繁瑣。列B中近1500條 – Neelesh

回答

0
Sub MyMacro() 
    Static curr As Range 
    If curr Is Nothing Then Set curr = Worksheets("Sheet2").Range("B1") 

    If curr.Value = vbNullString Then 
     MsgBox "No Value" 
     Exit Sub 
    End If 

    ' although Select is unrecommneded in VBA, but since it is required in the problem statement... 
    Worksheets("Sheet2").Activate 
    curr.Select 
    Worksheets("Sheet1").Range("L6").Value = curr.Value 
    Set curr = curr.Offset(1, 0) 
End Sub