Apply VBA to every other column

Reegs

New Member
Joined
Aug 25, 2014
Messages
20
Hello everyone, I have another question for you.

I'm making a training ledger and I am using the following VBA to double click a cell to change the cell to a check mark.

Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)


    If Not Intersect(Target, Range("H9:ABC2000")) Is Nothing Then


            Cancel = True 'Prevent going into Edit Mode


            Target.Font.Name = "Wingdings"


                If Target = vbNullString Then


                    Target = "ü"


                Else


                    Target = vbNullString


                End If


    End If


End Sub

I would like this VBA to work on every other column starting at "I"

I also need the same thing to work on every other column starting at "H" but fill in an "X" instead. (regular arial is fine)

"X" means required
"Check mark" means completed


Can anyone help me out?

Thanks,
Reegs
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
You can check to see if the column number of the Target cell is odd or even, i.e.
Code:
If Target.Column Mod 2 = 0 Then
'    Even numbered column, return "X" here
Else
'    Odd numbered column, return check mark here
End If
Just replace the comments with your appropriate code.
 
Last edited:
Upvote 0
You can check to see if the column number of the Target cell is odd or even, i.e.
Code:
If Target.Column Mod 2 = 0 Then
'    Even numbered column, return "X" here
Else
'    Odd numbered column, return check mark here
End If
Just replace the comments with your appropriate code.


Thanks Joe,

After MUCH tinkering, I was able to come up with the following:
Code:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)


  If Not Intersect(Target, Range("H9:ABC2000")) Is Nothing Then


            Cancel = True 'Prevent going into Edit Mode


    
                       
        If Target.Column Mod 2 = 0 Then


            Target.Font.Name = "Arial"
                   If Target = vbNullString Then
                    Target = "X"


                   Else
                   
                    Target = vbNullString
                    End If
         Else
            
            Target.Font.Name = "Wingdings"
                    If Target = vbNullString Then
                    Target = "ü"
        
                   Else
                   
                    Target = vbNullString
                    End If
         End If


     
 End If


It works !!!

Thanks again,
Reegs
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,689
Members
449,250
Latest member
azur3

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