+ Reply to Thread
Results 1 to 9 of 9

Selcet cases after first case not working

Hybrid View

Martinw94 Selcet cases after first case... 01-06-2020, 09:02 AM
Sintek Re: Selcet cases after first... 01-06-2020, 09:03 AM
romperstomper Re: Selcet cases after first... 01-06-2020, 09:33 AM
Martinw94 Re: Selcet cases after first... 01-06-2020, 10:10 AM
romperstomper Re: Selcet cases after first... 01-06-2020, 10:17 AM
Martinw94 Re: Selcet cases after first... 01-06-2020, 10:20 AM
Martinw94 Re: Selcet cases after first... 01-08-2020, 10:48 AM
Sintek Re: Selcet cases after first... 01-06-2020, 10:30 AM
Sintek Re: Selcet cases after first... 01-08-2020, 10:51 AM
  1. #1
    Registered User
    Join Date
    01-06-2020
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    4

    Selcet cases after first case not working

    Hello

    I have a problem where when I fill out a specific cell with "x" it's suppose to give a value in another worksheet. It's working for the first Select case, but cases that comes after isn't working.

    I Run a If Isempty code to start with to avoid a Mismatch error.

    My code Is

     Dim Value As Integer
      Dim Celle As String
    
    Celle = target.Address
       
        If IsEmpty(Range("H3,H10,H16,H24,H32,P3,P10,P21,P30,P38")) = True Then
            'do nothing
            
        Else
               
            If target.Value = "x" Then
        
        
                Select Case Celle
                
                    Case "$H$3"
                        Worksheets("Sheet2").Range("B2").Value = "1"
                
                    Case "$H$10"
                        Worksheets("Sheet2").Range("B2").Value = "2"
                        
                    Case "$H$16"
                        Worksheets("Sheet2").Range("B2").Value = "3"
                                     
                    Case "$H$24"
                        Worksheets("Sheet2").Range("B2").Value = "4"
                        
                    Case "$H$32"
                        Worksheets("Sheet2").Range("B2").Value = "5"
                
                    Case "$P$3"
                        Worksheets("Sheet2").Range("B2").Value = "6"
                        
                    Case "$P$10"
                        Worksheets("Sheet2").Range("B2").Value = "7"
                        
                    Case "$P$21"
                        Worksheets("Sheet2").Range("B2").Value = "8"
                        
                    Case "$P$30"
                        Worksheets("Sheet2").Range("B2").Value = "9"
                        
                    Case "$P$38"
                        Worksheets("Sheet2").Range("B2").Value = "10"
                        
            End Select
    
        
    End If
    End If
    
    End Sub
    Last edited by Martinw94; 01-17-2020 at 10:28 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Selcet cases after first case not working

    Hi Martinw94

    Welcome to our Forum...

    Please take a moment to read our forum rules...here
    Your post does not comply with Rule # 2
    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
     Your Code
    So...

    Edit your post
    Highlight the code and press the # button

    This post should receive no further attention until OP has complied...
    Last edited by Sintek; 01-06-2020 at 09:15 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,974

    Re: Selcet cases after first case not working

    This part:

    IsEmpty(Range("H3,H10,H16,H24,H32,P3,P10,P21,P30,P38"))
    returns True if H3 is empty and False otherwise.
    Everyone who confuses correlation and causation ends up dead.

  4. #4
    Registered User
    Join Date
    01-06-2020
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    4

    Re: Selcet cases after first case not working

    Thanks

    Do you have an idea on how to get it to check all of the cells then? :D

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,974

    Re: Selcet cases after first case not working

    If you want to test if they are all empty, you can use:

    If worksheetfunction.Counta(Range("H3,H10,H16,H24,H32,P3,P10,P21,P30,P38")) = 0 then

  6. #6
    Registered User
    Join Date
    01-06-2020
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    4

    Re: Selcet cases after first case not working

    Cheers thanks alot :D

  7. #7
    Registered User
    Join Date
    01-06-2020
    Location
    Denmark
    MS-Off Ver
    2013
    Posts
    4

    Re: Selcet cases after first case not working

    When i inserted this code the day before yesteday it work like a charm and now its not working :/
    I've tried removing all ranges except "H3" and when I do that It works. When I bring in the remaining cells it gives the following error: Method 'Range' of object' _Worksheet' Failed

    Can you help me out? Been trying to fix for hours now

  8. #8
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Selcet cases after first case not working

    Perhaps...Code in sheet1.module
    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim rng As Range
    Set rng = Sheet2.Range("B2")
    If Not Intersect(Target, Range("H3,H10,H16,H24,H32,P3,P10,P21,P30,P38")) Is Nothing Then
        Application.EnableEvents = False
        If Target = "x" Then
            Select Case Target.Address
                Case "$H$3"
                    rng = "1"
                Case "$H$10"
                    rng = "2"
                Case "$H$16"
                    rng = "3"
                Case "$H$24"
                    rng = "4"
                Case "$H$32"
                    rng = "5"
                Case "$P$3"
                    rng = "6"
                Case "$P$10"
                    rng = "7"
                Case "$P$21"
                    rng = "8"
                Case "$P$30"
                    rng = "9"
                Case "$P$38"
                    rng = "10"
            End Select
        End If
        Application.EnableEvents = True
    End If
    End Sub
    Last edited by Sintek; 01-06-2020 at 10:38 AM.

  9. #9
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    14,957

    Re: Selcet cases after first case not working

    this code the day before yesteday
    What code...Perhaps its time you upload a sample file....

+ 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. Replies: 2
    Last Post: 09-19-2017, 03:27 PM
  2. [SOLVED] Select case where value is numeric then select other cases
    By scottiex in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-06-2015, 11:03 PM
  3. [SOLVED] Userform : add value according selcet column range : Solved by (nilem)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-23-2014, 06:12 AM
  4. Add cases opened and closed for each month and specifics about the cases.
    By ChrisLaRoc in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-04-2014, 08:19 PM
  5. [SOLVED] code not working in all or all cases
    By s4driver in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-09-2013, 11:32 AM
  6. adding more cases to case statement
    By johnson1421 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2012, 10:49 AM
  7. Proper Case not working
    By duckboy1981 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2008, 08:21 AM

Tags for this Thread

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