回復 1#myleoyes
依據 InputBox 的說明,
這裡 Z 就是所選 Range 的參照, 故而 Z.Row 就是你要的列值囉.
Sub AA()
Dim Z As Range
[A1:C1] = ""
Set Z = Application.InputBox("請選取資料", " 來源數據", Type:=8)
If Z <= 0 Then Exit Sub
N = Z.Row 'N = ActiveCell.Row
[$D$1] = "=" & Z & "-" & N
[D1].Select
End Sub
複製代碼
作者: myleoyes 時間: 2013-10-14 21:33
回復 2#luhpro
前輩!謝謝!!N= Z.Row小弟有試過
問題是If Z <= 0 The Exit Sub
改為If Z <= 0 Then GoTo ag
當對話框選擇取消時
程式會錯誤424不知為何?
請前輩不吝再賜教謝謝再三!!作者: luhpro 時間: 2013-10-14 22:51
回復 4#luhpro
前輩!
謝謝!!小弟修改如下
Sub AA()
Dim Z As Range
On Error Resume Next
[A1:C1] = ""
ag:
Set Z = Application.InputBox("請選取資料", " 來源數據", Type:=8)
If Z <= 0 Then GoTo ag
N = Z.Row
[$D$1] = "=" & Z & "-" & N
[D1].Select
End Sub