Active Cell stored as a variable

richardson

New Member
Joined
Jul 12, 2006
Messages
11
Hi All -

Is there a way to store the location of the active cell and then after some calculations are done in different cells the macro would bring you back to the cell where you started and not the cell where information was changed. BTW the incoming active cell will be different every time.

Other background:
I have a macro that is using worksheet_change to drive it. So after every calculation the active cell is drive back to the one that the macro is correcting. This is annoying to my users because the form is two pages long and the macro points to a cell on the first page.

Thanks for any help.
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
How is the active cell being moved/changed in the first place?

Are you selecting/activating?

If you are then you probably don't need to, and therefore don't need to move back to the active cell because you've never moved from it.

Can you post your code?
 
Upvote 0
Code -dropdown based on another dropdown selection

Here is the code. Basically using the worksheet_change the user selects a dropdown from a list in e12 and then this macro runs and tells it what list to look at in i17. However this runs after every time a 'calculation' is done by excel. I have tried worksheet_selectionchange but when I use that I lose the ability to make a selection in my first dropdown.

(In case it isn't obvious, my codes are always cobbled and not elegant, hopefully you can swim your way through it.)



Private Sub worksheet_Change(ByVal Target As range)
If (range("e12").Value) = "APU" Then
range("i17").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
:=xlBetween
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
range("i17").Value = "blah blah blah"
ElseIf (range("e12").Value) = "ECS" Then
range("i17").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$D$1:$D$2"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ElseIf (range("e12").Value) = "EPS" Then
range("i17").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=$D$2:$D$3"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If

End Sub
 
Upvote 0
You need to isolate your target. What cells do you wnat to trigger the code? E12?. If so, use
Code:
If Target.Address <> "$E$12" Then Exit Sub
Also, use Select Case Target instead of If's

lenze
 
Upvote 0
Is the code only meant to be triggered if E12 is changed?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$E$12" Then
        Select Case Target.Value
            Case "APU"
                With Range("i17").Validation
                    .Delete
                    .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
                    :=xlBetween
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            Case Is = "ECS"
                With Range("i17")
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=$D$1:$D$2"
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            Case "EPS"
                With Range("i17")
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=$D$2:$D$3"
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
        End Select
    End If

End Sub
 
Upvote 0
Thanks. That worked. Does target.address mean activecell? Is it just a variable name for the active cell?
 
Upvote 0
Thanks. That worked. Does target.address mean activecell? Is it just a variable name for the active cell?

Target is the name assigned to the cell CHANGED as a Range. It may or may not be the active cell. If you use the Selection_Change event, Target is the cell selected. Likewise, using the Before_DoubleClick event sets the target as the cell doubleclicked. Target has the same properties as any other range. Examples: Address, Count, Column, Row, Font, Style, Interior, Borders, Name

lenze
 
Upvote 0

Forum statistics

Threads
1,203,061
Messages
6,053,307
Members
444,651
Latest member
markkuznetsov1

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top