Skip one cell on the first row.

Matrix335

New Member
Joined
Oct 5, 2015
Messages
27
Hello members,
I need help modifying the VBA code to skip a cell in the first row of each set of rows.
The lines highlighted in yellow are the first lines of the set, and every set contain 6 row. When i start entering the data on the first row, i want excel to skip A6 and move to A7 (Only for the yellow highlighted rows). The rest of the rows of each set should be as the same as in the attached photo.

Thank you.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    
    
    
    On Error Resume Next
    'ESTABLISH THE COLUMN AND ROW DIGITS
    Dim tAd As Variant
    tAd = Split(Target.Address, "$")
    'tAd(1) BECOMES THE COLUMN LETTER
    'tAd(2) BECOMES THE ROW NUMBER
    
    'ESTABLISH THE REMAINDER OF THE ROW NUMBER DIVIDED BY 5
    Dim rowRemainder As Long
    rowRemainder = tAd(2) Mod 6

    'IF THE COMPLETED ENTRY IS IN COLUMN A
    If tAd(1) = "B" Then
        Range("C" & Target.Row).Activate
 
    
    '...IN COLUMN C
    ElseIf tAd(1) = "C" Then
        Range("D" & Target.Row).Activate
        
    '...IN COLUMN D
    ElseIf tAd(1) = "D" Then
        Range("E" & Target.Row).Activate
        
    '...IN COLUMN E
    ElseIf tAd(1) = "E" Then
        Range("F" & Target.Row).Activate
          
                        
        
        
        
        
    '...IN COLUMN F
    ElseIf tAd(1) = "F" Then
        Range("G" & Target.Row).Activate
    
        
        
        'IF IN THE LAST ROW OF THE SET
        If rowRemainder = 1 Then
            Range("B" & Target.Row + 1).Activate
        
        'OTHERWISE IN THE UPPER PART OF THE SET
        Else
            Range("D" & Target.Row + 1).Activate
            
        End If
    End If
    
    
    
End Sub
 

Attachments

  • skip cell.jpg
    skip cell.jpg
    88.7 KB · Views: 11

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Have a try with these changes:
VBA Code:
        '...IN COLUMN E
    ElseIf tAd(1) = "E" Then
        If rowRemainder = "2" Then                '<- added
            Range("G" & Target.Row).Activate      '<- added
        Else                                      '<- added
            Range("F" & Target.Row).Activate
        End If
        '...IN COLUMN F
    ElseIf tAd(1) = "F" Then
        Range("G" & Target.Row).Activate
        'IF IN THE LAST ROW OF THE SET
        If rowRemainder = 1 Then
            Range("B" & Target.Row + 1).Activate
            'OTHERWISE IN THE UPPER PART OF THE SET
        Else
            Range("D" & Target.Row + 1).Activate
        End If
    ElseIf tAd(1) = "G" Then                      '<- added
        Range("D" & Target.Row + 1).Activate      '<- added
    End If
End Sub
 
Upvote 0
@rollis13
Seeing as I'd started to look at this, here is a slightly different way to achieve same.
Neither prevents the user from consciously selecting out of sequence but should otherwise auto-select in your required sequence.

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

'Ignore all if Target is multiple cells
If Not Target.Count = 1 Then Exit Sub
'Ignore if  entry not in columns B:F
If Target.Column < 2 Or Target.Column > 7 Then Exit Sub

Dim TCol As Integer
Dim OSCol As Integer
Dim OSRow As Long
'Establish Target column

TCol = Target.Column

OSCol = 1 'General column offset
OSRow = 0 'General row offset

'ESTABLISH THE REMAINDER OF THE ROW NUMBER DIVIDED BY 6
    Dim rowRemainder As Long
    rowRemainder = Target.Row Mod 6
    
'Do based upon target column
 Select Case TCol
    Case 7  'last column G only ever if first row
        OSRow = 1  'offset to next row
        OSCol = -3  'offset to D
    
    Case 6  'column F only ever last 5 rows in block
        'offsets vary with rowof block
        Select Case rowRemainder
            Case 2 To 5   'rows 2 to 5
                OSRow = 1 'offset to next row
                OSCol = -2  'offset to D
                
            Case 0  'last row, 6, of block
                OSRow = 1  'offset to next row
                OSCol = -4  'offset to B
           End Select
           
       Case 5  'E
            'offset to G if row 1 of block to skip col F
           If rowRemainder = 1 Then OSCol = 2
           
       Case Else
            'Otherwise the general offsets remain unaltered
                       
 End Select
Target.Offset(OSRow, OSCol).Activate

End Sub
 
Upvote 0
Have a try with these changes:
VBA Code:
        '...IN COLUMN E
    ElseIf tAd(1) = "E" Then
        If rowRemainder = "2" Then                '<- added
            Range("G" & Target.Row).Activate      '<- added
        Else                                      '<- added
            Range("F" & Target.Row).Activate
        End If
        '...IN COLUMN F
    ElseIf tAd(1) = "F" Then
        Range("G" & Target.Row).Activate
        'IF IN THE LAST ROW OF THE SET
        If rowRemainder = 1 Then
            Range("B" & Target.Row + 1).Activate
            'OTHERWISE IN THE UPPER PART OF THE SET
        Else
            Range("D" & Target.Row + 1).Activate
        End If
    ElseIf tAd(1) = "G" Then                      '<- added
        Range("D" & Target.Row + 1).Activate      '<- added
    End If
End Sub
This code works great.
One more thing, How can i show a msgbox of each value i entered?
 
Upvote 0
This would be a completely different question; for the rules of the forum you probably need to start a new thread.
Anyway, I don't understand the question.
What do you exactly mean with "show a msgbox" ? aren't you only inputting numbers ? do you mean that you need a summary of all number inputted ? if so, how does Excel understand that you have ended your inputting ?
Even if you continue here or start a new thread, please explain and give more information.
 
Upvote 0
This would be a completely different question; for the rules of the forum you probably need to start a new thread.
Anyway, I don't understand the question.
What do you exactly mean with "show a msgbox" ? aren't you only inputting numbers ? do you mean that you need a summary of all number inputted ? if so, how does Excel understand that you have ended your inputting ?
Even if you continue here or start a new thread, please explain and give more information.
Thank you.
 
Upvote 0
Thanks for the positive feedback(y), glad having been of some help.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top