Sub test()
Dim sheet1_b As Range, sheet1_c As Range, sheet1_d As Range
With Sheets("sheet1")
r1 = .[C65536].End(xlUp).Row
If r1 < 4 Then
MsgBox "没有数据!"
Exit Sub
End If
Set sheet1_b = .Range("B4:B" & r1)
Set sheet1_c = .Range("C4:C" & r1)
Set sheet1_d = .Range("D4:D" & r1)
End With
With Sheets("Sheet2")
r2 = [A65536].End(xlUp).Row + 1
.Range("A" & r2).Resize(r1 - 4 + 1, 1) = sheet1_c.Value
.Range("B" & r2).Resize(r1 - 4 + 1, 1) = sheet1_b.Value
.Range("C" & r2).Resize(r1 - 4 + 1, 1) = sheet1_c.Value
End With
End Sub
if workbooks("aaa.xls").sheets(1).range("B4")="" then
msgbox "没有数据"
exit sub
end if
意思是如果aaa簿中第一个工作表的B4单元格为空,就说明没有数据,退出程序