2014-01-16 55 views
1

我期待使用變量來查找範圍,然後使用這些變量來激活選擇。在Excel中使用變量範圍

這裏是我的代碼:

Dim first As Integer 
Dim Last As Integer 

first = (ActiveCell.Row + 1) 
Selection.End(xlDown).Select 
Last = (ActiveCell.Row - 1) 
Range(("J" & first) : ("J" & last)).Select 

不過,我得到這個語法錯誤在Excel VBA 2010

任何建議。

感謝,

回答

1

範圍語法範圍( 「A1:B2」),所以你將需要修改代碼:

Dim first As Integer 
Dim Last As Integer 

first = (ActiveCell.Row + 1) 
Selection.End(xlDown).Select 
Last = (ActiveCell.Row - 1) 
Range("J" & first & ":" & "J" & Last).Select 
+0

感謝。完美的作品。下一部分是如何在配方中使用它 - 現在發佈。 – SASUSMC