Q. How To Store Current Selection using VBA in Excel?
A. Use the foloowing VBA script:Option Explicit Private Sub Example() Dim ActSheet As Worksheet Dim SelRange As Range Set ActSheet = ActiveSheet Set SelRange = Selection '' Any code here 'Dim NewSheet As Worksheet ' 'ActiveSheet.Range("A1").Select ' 'Set NewSheet = ThisWorkbook.Sheets().Add() 'NewSheet.Move After:=Sheets(ThisWorkbook.Sheets().Count) ActSheet.Select SelRange.Select End Sub
Option Explicit
Dim ActSheet As Worksheet Dim SelRange As Range
Set ActSheet = ActiveSheet Set SelRange = Selection
ActSheet.Select SelRange.Select
No comments:
Post a Comment