PDA

Click to See Complete Forum and Search --> : Testing for cell values in Excel 97 ?


kburns1649
Nov 10th, 2003, 04:33 PM
I need to test the value in a cell that currently has validation turned on values displayed in a
list (combo box)

The routine in VBA is as follows:
Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
WorkID = ActiveCell().Text
If WorkID = "Flex" Then MsgBox "Please complete Flex-Time Form"
End Sub

My problem is that it only fires when I leave the cell and return back...How can I test the value in cell before, or as, I get to the next cell?

This is Excel '97
Thanks,

Granty
Nov 13th, 2003, 05:54 PM
workid = Me.Cells.SpecialCells(xlCellTypeLastCell).Text is how, but I have a feeling it will be tough. The message will fire as you leave the cell, but clicking the message box will fire the SelectionChange again and you'll be stuck in a loop.

Spajeoly
Nov 14th, 2003, 05:56 AM
Just make sure you check the ActiveCell.Address to be the right cell...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If ActiveCell.Address = "$A$1" Then
'All your code here
End If
End Sub

That way it will only fire on the cell you want to check, I use it all the time to turn cells into buttons. :D