Forum Discussion

Lorenzo Kim's avatar
Lorenzo Kim
Bronze Contributor
Jul 25, 2018

VBA to trap error for Column entry

The SUB below can capture the errors for non-letters and more than 3 characters for Column entry but can not detect if beyond XFD is entered. like XXX - it just looped! i.e. legit entry should be A ...
  • Man Fai Chan's avatar
    Jul 25, 2018

    The problem goes to the variable "mcol" when it is beyond XFD. You include a checking before the for-loop as below:

     

    check_col = Cells(1,mcol).column
    If check_col > 0 then
    ' it is good and okay to run the next steps
    else
    msgbox("Input does not refer to a column. ")
    exit sub
    end if

    I am not sure if there is other easier way to do. Hope that it can help you. 

Resources