View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Patrick C. Simonds Patrick C. Simonds is offline
external usenet poster
 
Posts: 343
Default MultiTab userform question

Thanks for your reply. I was able to use part of what you suggested If
Rng.Offset(0, 1) = "" Then

Rng.Clear
It works because the worksheet is still active.

Below is the subroutine I came up with, but I must be missing something. I
thought "MultiPage1_Exit" would only apply to page 1 of the 6 pages. But the
code runs every time I switch from one page to the next. How can I make this
run only when I leave Page1?



Private Sub MultiPage1_Exit(ByVal Cancel As MSForms.ReturnBoolean)

Set Rng = Cells(ActiveCell.Row, 1)
If Rng.Offset(0, 1) = "" Then
Rng.Clear
End If

End Sub


"OssieMac" wrote in message
...
Hi Patrick,

The following code is the only way I have been able to reference the
active
cell on a sheet which I deactivate. If anyone else reads this and has
other
options then I am certainly interested.

My method involves the following:-

Saving the name of the new sheet.
Re-activating the old sheet.
Assign the active cell to a variable.
Turn off events .
Re-select the new required worksheet.

Also your code 'rng = Cells(ActiveCell.Row, 1)'. If you want to assign a
range to a variable then it should have Set in front of it:-
Set rng = Cells(ActiveCell.Row, 1)

To put the following code in the correct place, right click on the
worksheet
name (tab) that is being deactivated and select View code. The VBA editor
will open in the right place.

Private Sub Worksheet_Deactivate()
Dim Rng As Range
Dim strNewSht As String

'Following line is for info only confirming the the new sheet
'is the active sheet before any of the code is processed.
MsgBox "Active Sheet is: " & ActiveSheet.Name

'Save the new sheet name
strNewSht = ActiveSheet.Name

'Select the original sheet
Sheets("Sheet1").Select

'Assign required range to a variable

Set Rng = Cells(ActiveCell.Row, 1)

'Disable events and re-select the new sheet
Application.EnableEvents = False
Sheets(strNewSht).Select
'Re-enable events
Application.EnableEvents = True

'Can now use the range as a reference to
'manipulate dat on the deactivated sheet
If Rng.Offset(0, 1) = "" Then
Rng.Clear
End If

End Sub

Regards,

OssieMac