+ Reply to Thread
Results 1 to 12 of 12

Adjust code to allow multi choice please?

Hybrid View

garyi Adjust code to allow multi... 01-15-2012, 12:29 PM
TMS Re: Adjust code to allow... 01-15-2012, 12:46 PM
p24leclerc Re: Adjust code to allow... 01-15-2012, 12:59 PM
garyi Re: Adjust code to allow... 01-15-2012, 03:19 PM
Richard Buttrey Re: Adjust code to allow... 01-15-2012, 04:09 PM
garyi Re: Adjust code to allow... 01-15-2012, 04:27 PM
garyi Re: Adjust code to allow... 01-16-2012, 03:01 PM
BarryTSL Re: Adjust code to allow... 01-15-2012, 01:01 PM
Richard Buttrey Re: Adjust code to allow... 01-15-2012, 01:08 PM
garyi Re: Adjust code to allow... 01-15-2012, 01:14 PM
p24leclerc Re: Adjust code to allow... 01-15-2012, 04:08 PM
garyi Re: Adjust code to allow... 01-16-2012, 03:51 PM
  1. #1
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Adjust code to allow multi choice please?

    Hi there, a kindly soul here gave me so code which sits within the sheet so nothing needs to be pressed.

    In essence if I pick yes from a pop up box then it whisks that row off to another sheet, and this works great.

    However I would now like to have Yes/No/Maybe in the pop up and depending on what is chosen determins where the line gets taken.

    I tried simply duplicating the code and changing Yes to No, but it said there was ambiguity with the name.

    Could someone help me please?

    So to conclude, if I select yes it does what it does now. If I select no it goes to sheet called No and if I chose maybe the line goes to a Maybe worksheet.

    Thanks for any help.

    Private Sub Worksheet_Change(ByVal Target As Range)
     Application.EnableEvents = False
    'Was change made to Column D?
      If Target.Column = 10 Then
    'If yes, was a Y entered?
       If Target = "Yes" Then
    'If Yes, Store Row number, Determine next empty Row in
    'Cleared sheet, Move Row, Delete Row
        delRow = Target.Row
          Target = ""
          nxtRow = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1
          Target.EntireRow.Cut Destination:=Sheets("Completed").Range("A" & nxtRow)
          Rows(delRow).EntireRow.Delete shift:=xlUp
       End If
      End If
     Application.EnableEvents = True
    End Sub

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,493

    Re: Adjust code to allow multi choice please?

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook. Don't upload a picture when you have a workbook question. None of us is inclined to recreate your data. Upload the workbook and manually add an 'after' situation so that we can see what you expect. In addition clearly explain how you get the results..
    To attach a file to your post, you need to be using the main 'New Post' or 'New Thread' page and not 'Quick Reply'.
    To use the main 'New Post' page, click the 'Post Reply' button in the relevant thread.

    On this page, below the message box, you will find a button labelled 'Manage Attachments'.
    Clicking this button will open a new window for uploading attachments.

    You can upload an attachment either from your computer or from another URL by using the appropriate box on this page.
    Alternatively you can click the Attachment Icon to open this page.

    To upload a file from your computer, click the 'Browse' button and locate the file.

    To upload a file from another URL, enter the full URL for the file in the second box on this page.
    Once you have completed one of the boxes, click 'Upload'.

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Adjust code to allow multi choice please?

    As I was not sure how your worksheet was contructed, I modified your macro so it will repond to a change in column J (10) which uses DATA VALIDATION which limits data to be Yes, No or Maybe. There is no popup at all.
    When you change the value of a cell in column J, your macro will react based on its value. You first have to create sheet "No" and sheet "Maybe"
    Private Sub Worksheet_Change(ByVal Target As Range)
     Application.EnableEvents = False
    'Was change made to Column D?
      If Target.Column = 10 Then
    'If yes, was a Y entered?
       If Target = "Yes" Then
        'If Yes, Store Row number, Determine next empty Row in
        'Cleared sheet, Move Row, Delete Row
          delRow = Target.Row
          Target = ""
          nxtRow = Sheets("Completed").Range("A" & Rows.Count).End(xlUp).Row + 1
          Target.EntireRow.Cut Destination:=Sheets("Completed").Range("A" & nxtRow)
          Rows(delRow).EntireRow.Delete shift:=xlUp
        ElseIf Target = "No" Then
          delRow = Target.Row
          Target = ""
          nxtRow = Sheets("No").Range("A" & Rows.Count).End(xlUp).Row + 1
          Target.EntireRow.Cut Destination:=Sheets("No").Range("A" & nxtRow)
          Rows(delRow).EntireRow.Delete shift:=xlUp
        
        ElseIf Target = "Maybe" Then
          delRow = Target.Row
          Target = ""
          nxtRow = Sheets("Maybe").Range("A" & Rows.Count).End(xlUp).Row + 1
          Target.EntireRow.Cut Destination:=Sheets("Maybe").Range("A" & nxtRow)
          Rows(delRow).EntireRow.Delete shift:=xlUp
        
       End If
      End If
     Application.EnableEvents = True
    End Sub

  4. #4
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Adjust code to allow multi choice please?

    Hi There I tried this one, I am not getting a debug problem or anything, however nothing has occured.

    I have attached my excel sheet if anyone can help.

    Just to clarify the dashboard sheet is where I will keep things that are current. Once complete I will pick from the pop up box in column J, as soon as its selected it will get dumped into the win/lose/maybe pile (sorry changed the names)

    I hope this makes sense, if there is a more simple way then thats fine.

    Thanks for the great suggestions.
    Attached Files Attached Files
    Last edited by garyi; 01-15-2012 at 03:24 PM.

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Adjust code to allow multi choice please?

    Hi,

    The values in your column 4 (D) have changed and no longer match the macro. I Assume you are now using column 10 (I). In which case alter the macro accordingly.

    You have also changed the destination sheets from "Completed", "No" & "Maybe" to "Lose", "Postponed" & Win. In which case you'll need to also change the IF test line.
    i.e.

    If LCase(Target) = "win" Or LCase(Target) = "postponed" Or LCase(Target) = "lose" Then
    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  6. #6
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Adjust code to allow multi choice please?

    Very odd, it was not working on my macbook but is fine on my main mac. Perhaps macros got disabled or something.

    Thats cool then, it all appears to work well.

    THanks again for everyones help.

  7. #7
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Adjust code to allow multi choice please?

    Hello everyone, sadly the sheet is not working correctly, when a line is moved to another page it simply copies over the last one, so there is only every one line on 'win', 'lose' etc. I wanted to to drop it into the next line.

    To my untrained eye the macro should do it but its not?

    Sorry to be a pain, I have attached my sheet
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    01-24-2011
    Location
    Sheppey
    MS-Off Ver
    Excel 2010
    Posts
    239

    Re: Adjust code to allow multi choice please?

    I added just 2 more if statements to see your selection and used aaa as a variable to select the correct sheet.
    Private Sub Worksheet_Change(ByVal Target As Range)
     Application.EnableEvents = False
    'Was change made to Column D?
      If Target.Column = 10 Then
    'If yes, was a Y entered?
       If Target = "Yes" Then aaa = "Completed"
       If Target = "No" Then aaa = "No"
       If Target = "Maybe" Then aaa = "Maybe"
    'If Yes, Store Row number, Determine next empty Row in
    'Cleared sheet, Move Row, Delete Row
        delRow = Target.Row
          Target = ""
          nxtRow = Sheets(aaa).Range("A" & Rows.Count).End(xlUp).Row + 1
          Target.EntireRow.Cut Destination:=Sheets(aaa).Range("A" & nxtRow)
          Rows(delRow).EntireRow.Delete shift:=xlUp
       End If
     Application.EnableEvents = True
    End Sub
    you can change the code to suit the sheet names you prefer.

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Adjust code to allow multi choice please?

    Hi,

    Was that a typo in your code where the change to be detected is in column 4 (D) but the macro refers to column 10?
    I assume it is column 4.

    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim delRow As Long, nxtRow As Long, stSheet As String
        Application.EnableEvents = False
        'Was change made to Column D?
        If Target.Column = 4 Then
            stSheet = Target
            If LCase(stSheet) = "yes" Then stSheet = "Completed"
            'If yes, was a Y entered?
            If LCase(Target) = "yes" Or LCase(Target) = "no" Or LCase(Target) = "maybe" Then
                'If Yes, Store Row number, Determine next empty Row in
                'Cleared sheet, Move Row, Delete Row
                delRow = Target.Row
                nxtRow = Sheets(stSheet).Range("A" & Rows.Count).End(xlUp).Row + 1
                Target.EntireRow.Cut Destination:=Sheets(stSheet).Range("A" & nxtRow)
                Rows(delRow).EntireRow.Delete shift:=xlUp
            End If
        End If
        Application.EnableEvents = True
    End Sub

  10. #10
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Adjust code to allow multi choice please?

    Yea well spotted, I had inserted an extra column and made some changes.

    I will give the suggestions a try thanks for everyones help.

  11. #11
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: Adjust code to allow multi choice please?

    I just tried your sheet and it seems to be working well. As soon as you change the cell in column J to Win/Loose/... it moves this line to the appropriat sheet.
    As your data starts at column B, you have to change the program to look at the nxtRow in column B and not in column A as it used to be. Otherwise, all lines are copied to the same line in the sheets.

    Except for this glitch, it works.

  12. #12
    Forum Contributor
    Join Date
    08-31-2010
    Location
    andover
    MS-Off Ver
    Excel 2007
    Posts
    102

    Re: Adjust code to allow multi choice please?

    Its OK I worked it out

+ 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