user4945729
user4945729

Reputation:

VBA: access sheet from userForm

I am trying to access my workbook and sheets while I am in a subroutine of my UserForm.

My macro starts when the focus in the worksheet is changed:

Sub Worksheet_SelectionChange(ByVal Target As Range)
    '...
End Sub

In my UserForm, I now wanted to define what happens when the red x on the top right is pressed. In that case I want to change the focus/selection in Sheet1 when that UserForm is closed. Though, I want to do this relative to the original position, so relative to Target or relative to the ActiveCell.

What works in the routine above is:

ActiveCell.Offset(0, 1).Select

However, I would like to do this in the routine below:

Sub UserForm_Terminate()
    Me.Hide
    'change focus here
    End
End Sub

I was able to select a cell with

Sheet1.Cells(3, 3).Select

but that is obviously not relative to the original position. Neither Target nor ActiveCell... are available in UserForm_Terminate

I hope anyone can help

Vincenz

Upvotes: 1

Views: 782

Answers (1)

to StackOverflow
to StackOverflow

Reputation: 124794

I'm not sure I fully understand what you're trying to achieve, but can't you simply use:

Application.ActiveCell

in UserForm_Terminate?

Upvotes: 1

Related Questions