ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro, worksheet, from where did I come? (https://www.excelbanter.com/excel-programming/320100-macro-worksheet-where-did-i-come.html)

Neal Zimm

Macro, worksheet, from where did I come?
 
Hi - Am novice in VB.
this is part of a macro I recorded to copy a range of cells.
I was working in the temp worksheet, and the sheets temp select statement
was based on my clicking.
I'd like to generalize this section to copy the 'blank pg' cells from any
worksheet.
User would highlight cells on his current worksheet and execute the macro to
copy back to his sheet. How do I find out the name of the sheet from whence
I came?
Code would be appreciated.

The Go To dialog box did not give me this last location.
How does something get into the Go To dialog box?

Sheets("blank pg").Select
ActiveCell.Range("A1:H20").Select
Selection.Copy
Sheets("temp").Select
Selection.Insert Shift:=xlDown
ActiveSheet.Paste
Application.CutCopyMode = False


Thanks much.
Neal Z

Neal Zimm

Macro, worksheet, from where did I come?
 
For other novices like me, I was able to dig out the answer myself. this code
gets me back to the sheet I came from.

Dim homesheet As Worksheet
Set homesheet = ActiveSheet 'gets the name

Sheets("different sheet").Select
'code to do your thing on this sheet

homesheet.Activate
'get you back to from where you came.


"Neal Zimm" wrote:

Hi - Am novice in VB.
this is part of a macro I recorded to copy a range of cells.
I was working in the temp worksheet, and the sheets temp select statement
was based on my clicking.
I'd like to generalize this section to copy the 'blank pg' cells from any
worksheet.
User would highlight cells on his current worksheet and execute the macro to
copy back to his sheet. How do I find out the name of the sheet from whence
I came?
Code would be appreciated.

The Go To dialog box did not give me this last location.
How does something get into the Go To dialog box?

Sheets("blank pg").Select
ActiveCell.Range("A1:H20").Select
Selection.Copy
Sheets("temp").Select
Selection.Insert Shift:=xlDown
ActiveSheet.Paste
Application.CutCopyMode = False


Thanks much.
Neal Z



All times are GMT +1. The time now is 07:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com