2013-09-30 45 views
0

我有一個宏選擇表中的東西。在宏的開始處保存選擇並將其設置爲在宏的結尾處相同?

在運行宏的主要部分之前,我想保存活動選擇,以便我可以在宏的末尾設置相同的選擇。

我試過下面的解決方案,但它不起作用。我會很感激的建議。

Dim rng As Range 

'Beginning of macro 
rng = Range(ActiveSheet.Selection) 'Object doesn't support this property or method 

'Main section 

'End of macro 
rng.Select 

回答

2

解決方案是去(+1)

爲了完整起見,您還可以在Address保存爲一個字符串的最佳方式:

Dim selectionAddress as String 
selectionAddress = Selection.Address //e.g. A1 is "$A$1" 

//Your macro 

Range(selectionAddress).Select //At end of macro select cell A1 
+0

尼斯,@AlexP!偉大的提示! – tmoore82

3

代替rng = Range(ActiveSheet.Selection),它應該是Set rng = Selection。通過tmoore82提供

相關問題