Copy range values one by one

前端 未结 1 1887
难免孤独
难免孤独 2021-01-29 17:03

I have two sheets, in which L6 of Sheet 1 will have a data from a range in sheet 2 B:B. I need a macro, upon a command it shall select B:B, then copy first cell value (B1) to L6

相关标签:
1条回答
  • 2021-01-29 17:19
    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
    
    0 讨论(0)
提交回复
热议问题