如题,当我点击下一个cell准备输入数字时,怎么判断刚才输入的哪个是否在范围内。
Private Sub MSFlexGrid1_LeaveCell()
Dim ts As Single
ts = Val(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col))
If MSFlexGrid1.Row = 2 Then
  If ts <= 0 Or ts > 3600 Then
  MsgBox "范围:0 - 3600 秒", vbExclamation, "注意"
  End If
Else
  If MSFlexGrid1.Row = 3 Then
  If ts < 190 Or ts > 700 Then
  MsgBox "范围:190 - 700nm", vbExclamation, "注意"
  End If
End If
End If
End Sub
我这样写 但是不行。

解决方案 »

  1.   

    你这个有啥问题? 后面要加exit sub...MsgBox "范围:0 - 3600 秒", vbExclamation, "注意"
    exit sub
      

  2.   

    列范围不一样当然要判断那一列,不过我认为在LeaveCell里面判断不好处理吧. 毕竟你也是用textbox来编辑的,不是直接在单元格上编辑的啊
      

  3.   

    找到之前写的一个,是编辑完后按enter确认的. 你参考下
    (如果不用enter确认,在文本框的lostfocus事件中判断吧,不过不推荐)
    Private Sub MSFlexGrid1_Click()
        With MSFlexGrid1
            Text1.Visible = True
            Text1.Move .ColPos(.Col), .RowPos(.Row), .ColWidth(.Col), .RowHeight(.Row)
            Text1.BackColor = &HC0FFC0
            Text1.Text = ""
            If .TextMatrix(.Row, .Col) = "" Then
               Text1.Text = ""
            Else
               Text1.Text = .TextMatrix(.Row, .Col)
            End If
            Text1.SelLength = Len(Text1.Text)
            Text1.SetFocus
        End With
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
        If KeyAscii <> 13 Then Exit Sub
        If Text1.BackColor = &HC0FFC0 Then
            Text1.Visible = False
            MSFlexGrid1.SetFocus
            '数据是否合法,这里判断
            '……略
            MSFlexGrid1.Text = Text1.Text
        End If
    End Sub
      

  4.   

    本帖最后由 bcrun 于 2011-03-27 21:28:40 编辑