Thread: Column Limit
View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Geoff Geoff is offline
external usenet poster
 
Posts: 371
Default Column Limit

Hi
I agree with your suggestion though I am still curious - it seems odd that
the construct:
'If Not Sheets(1).Columns(txt1.Text).Column 256 Then..... Else'
does not trap a terminal Type Mismatch when lesser values are accepted.
'Subscript out of range' or similar would seem more appropriate at this stage
of my pondering.

Geoff

"JDMils" wrote:

Off the top of my head:

On Error Resume Next
Debug.Print Sheets(1).Columns(colTxt).Column
If Err.Number = 13 Then
' Not a valid reference.
Debug.Print "Error"
Else
' Valid Reference.
Debug.Print "OK"
End If
On Error GoTo 0



--

|
+-- JDMils
|

"Geoff" wrote in message
...
Hi
I have a textbox on a form and want the user to input a column header.
How
can I prevent the user inputting a value greater than 'IV' ?

Inputting 'K' yields 11 in the test msgbox
Inputting 'KK' gives a 'Type Mismatch' error.

Private Sub txt1_Change()

txt1.Text = UCase(txt1.Text)

''' for syntax testing only
MsgBox Sheets(1).Columns(txt1.Text).Column

If Not Sheets(1).Columns(txt1.Text).Column 256 Then
''' do something
Else
MsgBox "No such column"
End If

End Sub

T.I.A.

Geoff