+ Reply to Thread
Results 1 to 10 of 10

Adding extra case to macro...

Hybrid View

  1. #1
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Adding extra case to macro...

    Hi, i have this code that works on the basis of people entering information.
    I just want to add more cases similar to case 11 but depending on what is typed in?

    thanks, and if anybody wants more info, please ask
    Michael

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    'editing in Chem Log and Disposed Shift
    
    
    Application.EnableEvents = False
    For Each cell In Target
        With cell
            Select Case cell.Column
                Case 10     'column J changed
                    Cells(.Row, 9) = Range("M3").Value
                Case 11     'column K changed to disposed
                    If LCase(.Value) = "disposed" Then
                        Cells(.Row, 12) = Date
                        Cells(.Row, 9) = Range("M3").Value
                        .EntireRow.Copy Worksheets("Disposed").Cells(Rows.Count, 1).End(xlUp)(2, 1)
                        .EntireRow.Delete
                   End If
            End Select
        End With
    Next cell
    Application.EnableEvents = True
    
    End Sub

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

    Re: Adding extra case to macro...

    Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    For Each cell In Target
        With cell
            Select Case cell.Column
                Case 10     'column J changed
                    Cells(.Row, 9) = Range("M3").Value
                Case 11     'column K changed to disposed
                    If LCase(.Value) = "disposed" Then
                        Cells(.Row, 12) = Date
                        Cells(.Row, 9) = Range("M3").Value
                        .EntireRow.Copy Worksheets("Disposed").Cells(Rows.Count, 1).End(xlUp)(2, 1)
                        .EntireRow.Delete
                   elseif .value = "john" then
                        msgbox "name is john"
                   End If
            End Select
        End With
    Next cell
    Application.EnableEvents = True
    
    End Sub
    If solved remember to mark Thread as solved

  3. #3
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Adding extra case to macro...

    such a small addition, thanks very much.
    btw is there anything that you can but in the -value = "john"- part that would mean anything else written do this?

    Thanks

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

    Re: Adding extra case to macro...

    i'm sorry, english is not my langage, can you explain in other words ?

  5. #5
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Adding extra case to macro...

    So if I had a cell that you could write "blue" in it would move that row, and if you wrote "red" it would move it somewhere else...
    So if someone wrote yellow or green or anything else neither would happen...

    So is there something that can be put so if it meets none of the above options it does something else like a msg box to tell you the only options are red or blue

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Adding extra case to macro...

    Hi, mmcgrail,

    your chosen example differs a lot from the code you supplied in the Opening Post - I think you would like to keep the other checks as well:
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngCell As Range
    
    Application.EnableEvents = False
    
    For Each rngCell In Target
      With rngCell
        Select Case rngCell.Column
          Case 10     'column J changed
            Cells(.Row, 9) = Range("M3").Value
          Case 11     'column K changed to disposed
            If LCase(.Value) = "disposed" Then
              Cells(.Row, 12) = Date
              Cells(.Row, 9) = Range("M3").Value
              .EntireRow.Copy Worksheets(Target.Value).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
              .EntireRow.Delete
            ElseIf LCase(.Value) = "cancelled" Then
              .EntireRow.Delete
            ElseIf LCase(.Value) = "postponed" Then
              Cells(.Row, 12) = Date
              Cells(.Row, 9) = Range("M3").Value
              .EntireRow.Copy Worksheets(Target.Value).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            End If
        End Select
      End With
    Next rngCell
    Application.EnableEvents = True
    
    End Sub
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

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

    Re: Adding extra case to macro...

    Private Sub Worksheet_Change(ByVal Target As Range)
    With Target
      If .Cells.Count > 1 Or .Value = "" Then Exit Sub
      If .Column = 11 And LCase(.Value) <> "red" And LCase(.Value) <> "blue" Then
        MsgBox "only 2 options allowed, red or blue"
        Target.ClearContents
        Target.Select
      End If
    End With
    End Sub

  8. #8
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Adding extra case to macro...

    Hi, yeah I was trying to explain it more easily...but obviously haven't...

    Yes I would like the other checks but if someone enter something that wasn't in the above cases then to show a message box saying so...

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Adding extra case to macro...

    Hi, mmcgrail,

    like this?
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rngCell As Range
    
    Application.EnableEvents = False
    
    For Each rngCell In Target
      With rngCell
        Select Case rngCell.Column
          Case 10     'column J changed
            Cells(.Row, 9) = Range("M3").Value
          Case 11     'column K changed to disposed
            If LCase(.Value) = "disposed" Then
              Cells(.Row, 12) = Date
              Cells(.Row, 9) = Range("M3").Value
              .EntireRow.Copy Worksheets(Target.Value).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
              .EntireRow.Delete
            ElseIf LCase(.Value) = "cancelled" Then
              .EntireRow.Delete
            ElseIf LCase(.Value) = "postponed" Then
              Cells(.Row, 12) = Date
              Cells(.Row, 9) = Range("M3").Value
              .EntireRow.Copy Worksheets(Target.Value).Cells(Rows.Count, 1).End(xlUp).Offset(1, 0)
            Else
              MsgBox "'" & Target.Value & "' isnīt known for this case"
            End If
        End Select
      End With
    Next rngCell
    Application.EnableEvents = True
    
    End Sub
    Ciao,
    Holger

  10. #10
    Registered User
    Join Date
    02-28-2013
    Location
    Harrogate, England
    MS-Off Ver
    Excel 2007
    Posts
    44

    Re: Adding extra case to macro...

    thats it! Im amazed that i didnt work that out myself!

    thanks very much Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Vba code for remove extra full stops, and make sentence case.
    By satputenandkumar0 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-11-2013, 04:04 AM
  2. [SOLVED] adding target lines into graphs without adding an extra column of data
    By ea223 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-16-2013, 12:32 PM
  3. Replies: 8
    Last Post: 08-27-2012, 04:37 PM
  4. extra hours adding money for each extra hour worked FORMULA
    By cynthiamcastro in forum Excel General
    Replies: 3
    Last Post: 06-18-2012, 11:27 AM
  5. Adding extra data to existing Macro
    By rushdenx1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-08-2011, 04:40 AM

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