我有两张纸,其中纸张1的L6将具有来自纸张2 B:B中的范围的数据。我需要一个宏,根据命令选择B:B,然后将第一个单元格值(B1)复制到sheet1的L6,下次单击时应选择B2,并在达到最后一个值或空白时将值复制到L6它应该显示一条消息"没有值"。
答案 0 :(得分: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