Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return to origin cell at the end of a macro 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello,

I am looking for a way to somehow make to macro remember the cell which was activated when the macro was started and then at the end of some operations make the macro return to it.

Doe anybody know how to do this?

Thanks for ny help!!

Jan
 
Code:
' beginning of macro
dim rem_rng as range
set rem_rng = activesheet.selection

'your code here

' end of your code

rem_rng.select
set rem_rng = nothing
end sub
 
Forget the above, it'll give you an error!

Code:
Dim rem_rng As Range, rem_sht As Worksheet
Set rem_rng = Selection
Set rem_sht = ActiveSheet

' YOUR CODE GOES HERE

rem_sht.Select
rem_rng.Select
Set rem_rng = Nothing
Set rem_sht = Nothing
End Sub
 
Are you sure you need to change the active (selected) cell with your code ?

Using VBA code should allow you to carry most if not all operations on cells without actually selecting them. You code should also run faster as a result. For example the following code will color all cells in A1 to B10 red without actually selecting any of them.

Dim rngCell As Range
For Each rngCell In Range("A1:B10")
rngCell.Interior.ColorIndex = 3
Next

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top