+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 19

Thread: Select the next column and start on line 4 when a condition is satisfied.

  1. #1
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Select the next column and start on line 4 when a condition is satisfied.

    Hi there,

    I would like Excel to select the next col starting on row 4 when the target.row hits line 11. I have the following code so far:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Range("2:2").Interior.ColorIndex = xlNone
        Range("A:A").Interior.ColorIndex = xlNone
        Range("A" & Target.Row).Interior.ColorIndex = 23
        Cells(2, Target.Column).Interior.ColorIndex = 23
        
        If Cells(Target.Row) = 11 Then
        Cells(Target.Row - 7, 1).Select
        End If
       
    End Sub
    While I'm getting no error, it doesn't actually go to the next col and start on row 4.

    Any ideas?

  2. #2
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    try this
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Cells.Interior.ColorIndex = xlNone
    Cells(2, Target.Column).Interior.ColorIndex = 23
    Cells(Target.Row, 1).Interior.ColorIndex = 23
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
            Cells(2, Target.Column + 1).Interior.ColorIndex = 23
        
        End If
        
        
    End Sub
    Last edited by tom1977; 02-09-2012 at 03:01 PM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  3. #3
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    nice, thanks!

    By the way, what does this line of code do?
    Cells.Interior.ColorIndex = xlNone

  4. #4
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    it clears all color cells in all worksheet

    I replaced this
    Range("2:2").Interior.ColorIndex = xlNone
    Range("A:A").Interior.ColorIndex = xlNone
    with this
    Cells.Interior.ColorIndex = xlNone
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  5. #5
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    I see.

    I was exploring more on how to best go about entering numbers into the sheet with enhanced visualization.

    One of the things I would like to do is to make the font size of the target cell bigger when selected, and you when you move to the next cell, the font size goes back to its original font size.

    How much code change does this involve?

    Currently I have:

    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Cells.Interior.ColorIndex = xlNone
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        
        With ActiveCell
        .Interior.ColorIndex = 43
        .Font.Size = 14
        End With
        
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
    
    End Sub
    THanks

  6. #6
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Cells.Interior.ColorIndex = xlNone
        Cells.Font.Size = 10
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        
        With ActiveCell
        .Interior.ColorIndex = 43
        .Font.Size = 14
        End With
        
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
    
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  7. #7
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    wow nice.

    How do I add a numeric check ONLY on range B4 to P10?

    I know how to do it if the format is applied to the entire column, but what if i only want to add a check on range B4 to P10?

    So...say if a alphabetic letter is put in instead of a number, it erases the value and prompts users to re-enter a numeric value.

    Any ideas?

  8. #8
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    ??

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Cells.Interior.ColorIndex = xlNone
        Cells.Font.Size = 10
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        
        With Target
            .Interior.ColorIndex = 43
            .Font.Size = 14
        End With
        
        If Not IsNumeric(Target) Then
            Target.ClearContents
            MsgBox "this is not number"
        End If
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
    
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  9. #9
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Yes, I have exactly the same code in my mind, but I guess it would be almost better if there was a specified range in which the numeric check can be applied.

    For example, row 2 and 3 contain texts, which is fine because they are just headers. However, as soon as you move to row 4 and if you put in a letter instead of number, I would like your added code to activate.

    Does this make sense?

    By the way, I think it's better to put that numeric check in the worksheet_change event.
    Last edited by Lifeseeker; 02-09-2012 at 04:16 PM.

  10. #10
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Any one able to assist further on this?

  11. #11
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    yesterday was late on my part of globe

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Cells.Interior.ColorIndex = xlNone
        Cells.Font.Size = 10
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        If Target.Count = 1 Then
        With Target
            .Interior.ColorIndex = 43
            .Font.Size = 14
        End With
        If Target.Row < 11 And Target.Row > 3 Then
        If Not IsNumeric(Target) Then
            Target.ClearContents
            MsgBox "this is not number"
        End If
        End If
        End If
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
    
    End Sub
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  12. #12
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Hey, it's not exactly working, but the syntax is correct though..

       
        Cells.Interior.ColorIndex = xlNone
        Cells.Font.Size = 14
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        
        With Target
            .Interior.ColorIndex = 43
            .Font.Size = 18
        End With
        
        If Target.Row > 4 And Target.Row < 11 Then
        If Not IsNumeric(Target) Then
            Target.ClearContents
            MsgBox "this is not number"
        End If
        End If
        
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
    That line you added seems to suggest to limit the range to be checked.

  13. #13
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Hi
    Why You ereased this line?
    If Target.Count = 1 Then
    try to select two cells and watch what is happening with your code without this.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say thanks.

  14. #14
    Valued Forum Contributor
    Join Date
    10-21-2011
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    423

    Re: Select the next column and start on line 4 when a condition is satisfied.

    When I copied over your code, I only copied the line with the range check but not the entire code, which is why I missed that line.

    However, I keep thinking that this numeric check should be in the worksheet_change event, so the code below shows how it is laid out, but it is not working. I wonder if it is because I put it in the worksheet_change event instead of worksheet_selectionchange...

    hmm

    Private Sub Worksheet_Change(ByVal Target As Range)
     
    If Target.Row > 4 And Target.Row < 11 Then
        If Not IsNumeric(Target) Then
            Target.ClearContents
            MsgBox "this is not a number!"
        End If
    End If
    
    End Sub
    
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        
        Cells.Interior.ColorIndex = xlNone
        Cells.Font.Size = 14
        Cells(2, Target.Column).Interior.ColorIndex = 27
        Cells(Target.Row, 1).Interior.ColorIndex = 26
        
        If Target.Count = 1 Then
        With Target
            .Interior.ColorIndex = 43
            .Font.Size = 18
        End With
        End If
        
        If Target.Row > 11 Then
        Cells(4, Target.Column + 1).Select
        Cells(2, Target.Column + 1).Interior.ColorIndex = 27
        End If
        
    End Sub

  15. #15
    Valued Forum Contributor
    Join Date
    09-27-2011
    Location
    Poland
    MS-Off Ver
    Excel 2007
    Posts
    895

    Re: Select the next column and start on line 4 when a condition is satisfied.

    Like for me it works quite well
    Last edited by tom1977; 02-10-2012 at 09:34 AM.
    Regards

    tom1977

    If You are satisfied with my solution click the small star icon on the left to say 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.2.0