Need help w/VB code


Posted by Lauren on February 10, 2002 8:00 PM

Hello,

I have a workbook that consists of 5 pages and am stuck on working out the code to perform an action. The first four worksheets are a breakdown of certain subjects pertaining to a school. I have written code (which is attached to a macro on a toolbar) so someone can click on a particular cell in one of the first 4 worksheets, and that row will be copied and pasted to sheet # 5, which personalises each teachers selection. I then want to return to the original sheet (Be it worksheet 1, 2, 3 or 4) so more selections can be made.

I have it pretty well worked out, but at the moment I have only figured out the code to return to a particular sheet - at the moment it's
'Sheets.("Band 1").Select'

How can I return from the personalised sheet to whatever the last sheet was (that is , where the info was copied from), regardless of which of the other 4 sheets it was. Do I need an IF...Then...Else statement? If so, what is it? At the moment my worksheets are 'Band 1', 'Band 2', 'Band 3', 'Band 4', and 'My Worksheet'.

Any help would be greatly appreciated. I would have thought there would have been something like a 'Go to previous worksheet' function, but that only literally goes to the worksheet situated before on the tabs, not to the previous one actually used.

Here's hoping for some help!! Many thanks,

Lauren



Posted by Russell Hauf on February 10, 2002 8:38 PM

Well, without seeing your code I would say that you just need to capture the sheet (probably just the name would suffice) before you switch over to your "paste sheet". Something like this:

Sub MyPasteMacro()
'...
shtOriginal = ActiveSheet.Name

' copy and paste your data ...

Sheets(shtOriginal).Select

End Sub

Hope this helps,

Russell