PDA

View Full Version : Excel Macro Value Comparison


adalton
May 28, 2009, 03:55 PM
I am creating a function in my macro to check to see if the value of a cell's 2nd digit is equivalent to some number. Say check if it is a 2 so 1234, 4244, 5255, x2xx all would work, then if so I want to insert a column there. Is this possible?

JBeaucaire
May 28, 2009, 05:19 PM
This little macro will evaluate the ACTIVECELL. You can adapt this for your uses, I imagine:

Sub CheckDigit()
Dim MyVal As Boolean
MyVal = Mid(ActiveCell, 2, 1) = 2
If MyVal = True Then ActiveCell.EntireColumn.Insert (xlShiftToRight)
End Sub

adalton
May 28, 2009, 06:19 PM
Excellent. Thanks!