+ Reply to Thread
Results 1 to 7 of 7

Run code on any selection from validation list

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Run code on any selection from validation list

    Hello all,
    I have a long piece of code currently attached to a button, but I would like to code to run whenever a selection is made from the dropdown list in cell C4 in the 'Feedback' sheet. The code starts
    Sub mcrpasteformulaandcommentlist()
        ActiveWindow.SmallScroll Down:=23
        Range("C50").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(R[-43]C[1]=""y"",(CONCATENATE(""Well Done "",LEFT(R4C3,FIND("" "",R4C3)-1),"" you have completed "",R[-43]C[-2],"" "",R[-43]C)),IF(R[-43]C[1]=""n"",CONCATENATE(""Please use the "",R[-43]C[-2],"" user guide to complete "",R[-43]C),IF(R[-43]C[1]=""I"",""Teacher Comment Required"","""")))"
        Range("C51").Select
        ActiveWindow.SmallScroll Down:=-36
        Range("G7").Select
        ActiveCell.FormulaR1C1 = _
            "=IF(RC[-3]=""y"",(CONCATENATE(""Well Done "",LEFT(R4C3,FIND("" "",R4C3)-1),"" you have completed "",RC[-6],"" "",RC[-4])),IF(RC[-3]=""n"",CONCATENATE(""Please use the "",RC[-6],"" user guide to complete "",RC[-4]),IF(RC[-3]=""I"",""Teacher Comment Required"","""")))"
        Range("G7").Select
        Selection.AutoFill Destination:=Range("G7:G26")
        Range("G7:G26").Select
        Range("G7:G26").Select
        Range("G8").Activate
    there is more code after that but I couldn't insert it here. Is there a prefix or coding for applying this to the validation list selection?

    Many Thanks!

    Luke
    Attached Files Attached Files
    Last edited by lukestkd; 09-30-2012 at 10:01 AM.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Run code on any selection from validation list

    Private Sub Worksheet_Change(ByVal Target As Range)
    if Target = range("C4") then mcrpasteformulaandcommentlist
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: Run code on any selection from validation list

    Hi Patel45.
    Many thanks for your reply. The code is returning the error "Run Time Error: 13 Type Mismatch" VB is highlighting this section
    If Target = Range("C4")

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Run code on any selection from validation list

    did you put the macro on 'Feedback' sheet ? can you attach a sample file ?

  5. #5
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: Run code on any selection from validation list

    Hi Patel45, yes I did put it in the feedback sheet. wb attached.

    Cheers

  6. #6
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: Run code on any selection from validation list

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address = "$C$4" Then Call mcrpasteformulaandcommentlist
    End Sub

  7. #7
    Forum Contributor
    Join Date
    07-30-2012
    Location
    Leeds
    MS-Off Ver
    Excel 2013
    Posts
    177

    Re: Run code on any selection from validation list

    working perfectly! Many Thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1