Hi
I encountered some problem, hope you can help me.
I'm executing some macro by pushing a button in my worksheet.
During the macro I'm activating another sheet in another xsl file and collecting data from it.
at the end I need to go back to my original sheet(where the button located) and activate it to update a chart on this sheet.
how can I recognize the name of the sheet, so I will be able to activate it at the end of the macro? or is there any other way to activate previous sheet?
hope the problem is understandable.
Thanks!
Last edited by michael.g; 11-19-2009 at 06:23 AM.
I am currently developing an awesome solution to this problem, please stand by.
found how to do it
ActiveWindow.ActivatePrevious
thanks!
The insinuation from your post is that your code activates other sheets (which is probably not necessary).
If your code is on the worksheet in question, you can simply refer to 'me' e.g.:
but if you post your macro, it could probably be tidied up more thoroughly.me.cells(1,1).interior.fontcolor = 213432
CC
You have not provided the code, so I will use a simple scenario.
2 workbooks "Book1" and "Book2", you want to copy Book1,Sheet1,A1 and paste it to Book2,Sheet1,A1.
With both workbooks open you would use the macro recorder and end up with a code like this, these codes will be in Book2
The following code will do the same thing without having to physically select Book1 to get the data.Sub Macro7() Windows("Book1").Activate Sheets("Sheet1").Select Range("A1").Select Selection.Copy Windows("Book2").Activate Sheets("Sheet1").Select Range("A1").Select ActiveSheet.Paste Application.CutCopyMode = False End Sub
This may work as well.Sub GetData1() Dim wb1 As Workbook, wb2 As Workbook, _ ws1 As Worksheet, ws2 As Worksheet, c As Range, p As Range Set wb1 = Workbooks("Book1") Set wb2 = Workbooks("Book2") Set ws1 = wb1.Worksheets("Sheet1") Set ws2 = wb2.Worksheets("Sheet1") Set c = ws1.Range("A1") Set p = ws2.Range("A1") c.Copy Destination:=p End Sub
Sub GetData2() Workbooks("Book2").Worksheets("Sheet1").Range("A1") = Workbooks("Book1").Worksheets("Sheet1").Range("A1") End Sub![]()
Last edited by davesexcel; 11-19-2009 at 07:02 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks