Code to run macros from drop downlist, but undo if another macro is run.

Elnicko

New Member
Joined
Aug 17, 2011
Messages
31
Hi all I started using vba yesterday and im trying to edit this code.

I have 1000 cells with dropdown lists in them in colum I, this needs to be applied to all of them. (their all the same)

And If a different value is selected I need it to undo the last Marco.

Is this possible

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$I$9" Then
If Target = "Paul" Then
MacroA
ElseIf Target = "Rachel" Then
MacroB
ElseIf Target = "Julija" Then
MacroC
ElseIf Target = "Sue" Then
MacroD

End If
End If
End Sub
 
I'll be honest I don't completely understand how it works.
But it works and its nothing short of amazing!!

I have only ever used basic functions in Excel and this is a new world for
me nothing short of exciting. I see I have a whole lot to learn.

Thankyou so much.

If you don't mind can I ask you one last question?

Is it possible to have the marco place a link in cell m to where the data is pushed to?
 
Upvote 0

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
                    With ThisWorkbook.Worksheets(Target.Text)
                        lNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                        .Range("A" & lNextRow).Value = Target.Offset(, -1).Value
                        .Range("E" & lNextRow).Value = Target.Offset(, -3).Value & Target.Offset(, -2).Value
                        .Range("F" & lNextRow).Value = Target.Offset(, 1).Value
                        .Range("Z" & lNextRow).Value = Target.Address(0, 0)
                        [COLOR="Green"]'Hyperlink[/COLOR]
[COLOR="Red"]                        ActiveSheet.Hyperlinks.Add Anchor:=Target.Offset(, 4), _
                                                   Address:="", _
                                                   SubAddress:="'" & Target.Text & "'!" & Rows(lNextRow).Address, _
                                                   TextToDisplay:="Row " & lNextRow[/COLOR]
                    End With
 
Upvote 0
Works like a charm.
Thank you for all your help.

I'm amazed at the speed you have come up with these solutions.
Time for me to do some tutorials I think.

Have a great day
 
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    Dim lNextRow As Long, bSheetExists As Boolean
    
    If Target.Count = 1 And Target.Column = 9 Then
        If Target.Row >= 9 And Target.Row <= 1000 And Target.Row / 3 = Int(Target.Row / 3) Then
            On Error Resume Next
                ' Delete Named Range if exists (Undo last)
                Range("Link" & Target.Address(0, 0)).EntireRow.Delete
                ' Test if Worksheet from drop down list exists
                bSheetExists = Sheets(Target.Text).Name <> ""
            On Error GoTo 0
            If Target.Value = "" Then
                ' Clear previous hyperlink
                Target.Offset(, 4).ClearContents
                Target.Offset(, 4).Hyperlinks.Delete
            Else
                ' Log values and create link
                If bSheetExists Then
                    ' Log to selected sheet
                    With ThisWorkbook.Worksheets(Target.Text)
                        lNextRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
                        .Range("A" & lNextRow).Value = Target.Offset(, -1).Value
                        .Range("E" & lNextRow).Value = Target.Offset(, -3).Value & Target.Offset(, -2).Value
                        .Range("F" & lNextRow).Value = Target.Offset(, 1).Value
                    End With
                    ' Create Named Range and Hyperlink
                    ActiveWorkbook.Names.Add Name:="Link" & Target.Address(0, 0), RefersToR1C1:="='" & Target.Text & "'!R" & lNextRow
                    Target.Offset(, 4).Formula = "=""Row ""&ROW(Link" & Target.Address(0, 0) & ")"
                    ActiveSheet.Hyperlinks.Add Anchor:=Target.Offset(, 4), _
                                               Address:="", _
                                               SubAddress:="Link" & Target.Address(0, 0), _
                                               ScreenTip:="Click to follow."
                Else
                    MsgBox "Cannot locate a worksheet named " & Target.Text, vbExclamation, "Sheet Does Not Exist"
                End If
            End If
        End If
    End If
End Sub
 
Last edited:
Upvote 0
Works great thanks!

But If I sort and filter it doesn't carry the named range?
Is there any way to do this?
 
Upvote 0

Forum statistics

Threads
1,224,568
Messages
6,179,595
Members
452,927
Latest member
whitfieldcraig

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