PC Review


Reply
Thread Tools Rate Thread

Check for data in cell

 
 
oldjay
Guest
Posts: n/a
 
      6th Mar 2010
I want to check to be sure the cell selected in column C has data in it
otherwise display an error message.
 
Reply With Quote
 
 
 
 
Wouter HM
Guest
Posts: n/a
 
      6th Mar 2010
Hi oldjay

You can use the worksheet event shown below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' Be sure to look at a single cell
If Target.Cells.Count = 1 Then
' Check if a cell iu column C is selected
If Target.Column = 3 Then
' Check id the selected cell is empty
If IsEmpty(Target) Then
MsgBox "On empty cell"
End If
End If
End If
End Sub


HTH,

Wouter
 
Reply With Quote
 
oldjay
Guest
Posts: n/a
 
      7th Mar 2010
This code must be inserted in a sub routine so that the code doesn't continue
if a empty cell has been selected. as written it gives an error 424 'Object
required"

"Wouter HM" wrote:

> Hi oldjay
>
> You can use the worksheet event shown below:
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> ' Be sure to look at a single cell
> If Target.Cells.Count = 1 Then
> ' Check if a cell iu column C is selected
> If Target.Column = 3 Then
> ' Check id the selected cell is empty
> If IsEmpty(Target) Then
> MsgBox "On empty cell"
> End If
> End If
> End If
> End Sub
>
>
> HTH,
>
> Wouter
> .
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      7th Mar 2010
Give this a shot.

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 3 And Target.Cells.Count = 1Then
If Not IsEmpty(Target) And Target <> "" Then
MsgBox "Has Data"
Else
MsgBox "No Data"
End If
End If
End Sub



"oldjay" <(E-Mail Removed)> wrote in message
news:021EA369-6EF5-4787-AF5E-(E-Mail Removed)...
> This code must be inserted in a sub routine so that the code doesn't
> continue
> if a empty cell has been selected. as written it gives an error 424
> 'Object
> required"
>
> "Wouter HM" wrote:
>
>> Hi oldjay
>>
>> You can use the worksheet event shown below:
>>
>> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> ' Be sure to look at a single cell
>> If Target.Cells.Count = 1 Then
>> ' Check if a cell iu column C is selected
>> If Target.Column = 3 Then
>> ' Check id the selected cell is empty
>> If IsEmpty(Target) Then
>> MsgBox "On empty cell"
>> End If
>> End If
>> End If
>> End Sub
>>
>>
>> HTH,
>>
>> Wouter
>> .
>>



 
Reply With Quote
 
oldjay
Guest
Posts: n/a
 
      7th Mar 2010
I inserted Call Worksheet_SelectionChange and Call
Worksheet_SelectionChange(ByVal Target As Range) as the first line of my
Command Button to check for a proper selection but get an error message
"Argument not Optional"

"JLGWhiz" wrote:

> Give this a shot.
>
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> If Target.Column = 3 And Target.Cells.Count = 1Then
> If Not IsEmpty(Target) And Target <> "" Then
> MsgBox "Has Data"
> Else
> MsgBox "No Data"
> End If
> End If
> End Sub
>
>
>
> "oldjay" <(E-Mail Removed)> wrote in message
> news:021EA369-6EF5-4787-AF5E-(E-Mail Removed)...
> > This code must be inserted in a sub routine so that the code doesn't
> > continue
> > if a empty cell has been selected. as written it gives an error 424
> > 'Object
> > required"
> >
> > "Wouter HM" wrote:
> >
> >> Hi oldjay
> >>
> >> You can use the worksheet event shown below:
> >>
> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >> ' Be sure to look at a single cell
> >> If Target.Cells.Count = 1 Then
> >> ' Check if a cell iu column C is selected
> >> If Target.Column = 3 Then
> >> ' Check id the selected cell is empty
> >> If IsEmpty(Target) Then
> >> MsgBox "On empty cell"
> >> End If
> >> End If
> >> End If
> >> End Sub
> >>
> >>
> >> HTH,
> >>
> >> Wouter
> >> .
> >>

>
>
> .
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      7th Mar 2010
The code should have been put in the worksheet code module if the title line
of Private Sub Worksheet_SelectionChange() is used. Then when you select a
cell on the worksheet, if it is in column C it will trigger the procedure.
If you want to use a command button to run the procedure, you will need it
written differently and the procedure to check the cells should be put in
the public module.

For the command button:

Private Sub CommandButton1_Click()
Call ChkColC
End Sub

For the public Module1

Sub ChkColC()
If ActiveCell.Column = 3 Then
If Not IsEmpty(ActiveCell) And ActiveCell <> "" Then
MsgBox "Has Data"
Else
MsgBox "No Data"
End If
End If
End Sub





"oldjay" <(E-Mail Removed)> wrote in message
news:5DAE4BD5-081B-4E56-A476-(E-Mail Removed)...
>I inserted Call Worksheet_SelectionChange and Call
> Worksheet_SelectionChange(ByVal Target As Range) as the first line of my
> Command Button to check for a proper selection but get an error message
> "Argument not Optional"
>
> "JLGWhiz" wrote:
>
>> Give this a shot.
>>
>> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> If Target.Column = 3 And Target.Cells.Count = 1Then
>> If Not IsEmpty(Target) And Target <> "" Then
>> MsgBox "Has Data"
>> Else
>> MsgBox "No Data"
>> End If
>> End If
>> End Sub
>>
>>
>>
>> "oldjay" <(E-Mail Removed)> wrote in message
>> news:021EA369-6EF5-4787-AF5E-(E-Mail Removed)...
>> > This code must be inserted in a sub routine so that the code doesn't
>> > continue
>> > if a empty cell has been selected. as written it gives an error 424
>> > 'Object
>> > required"
>> >
>> > "Wouter HM" wrote:
>> >
>> >> Hi oldjay
>> >>
>> >> You can use the worksheet event shown below:
>> >>
>> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> >> ' Be sure to look at a single cell
>> >> If Target.Cells.Count = 1 Then
>> >> ' Check if a cell iu column C is selected
>> >> If Target.Column = 3 Then
>> >> ' Check id the selected cell is empty
>> >> If IsEmpty(Target) Then
>> >> MsgBox "On empty cell"
>> >> End If
>> >> End If
>> >> End If
>> >> End Sub
>> >>
>> >>
>> >> HTH,
>> >>
>> >> Wouter
>> >> .
>> >>

>>
>>
>> .
>>



 
Reply With Quote
 
Wouter HM
Guest
Posts: n/a
 
      7th Mar 2010
Hi,

To create a worksheet event, as my example is, open the VBE. (Use [Alt]
+[F11]).
Dubble click on the sheet where you want the event to be.
To make the project visible you might need to hit [Ctrl]+[R].
Enter the code.

Sorry, The events can no be called as yu tried.

Hoop this makes thing clear to you.

Wouter
 
Reply With Quote
 
oldjay
Guest
Posts: n/a
 
      7th Mar 2010
Thanks

That runs so well I thought I might ask you
for the code that will be inside a macro. If the selected cell =214 then
check to be sure there is a value greater than zero in cell R1 if not error
message

"JLGWhiz" wrote:

> The code should have been put in the worksheet code module if the title line
> of Private Sub Worksheet_SelectionChange() is used. Then when you select a
> cell on the worksheet, if it is in column C it will trigger the procedure.
> If you want to use a command button to run the procedure, you will need it
> written differently and the procedure to check the cells should be put in
> the public module.
>
> For the command button:
>
> Private Sub CommandButton1_Click()
> Call ChkColC
> End Sub
>
> For the public Module1
>
> Sub ChkColC()
> If ActiveCell.Column = 3 Then
> If Not IsEmpty(ActiveCell) And ActiveCell <> "" Then
> MsgBox "Has Data"
> Else
> MsgBox "No Data"
> End If
> End If
> End Sub
>
>
>
>
>
> "oldjay" <(E-Mail Removed)> wrote in message
> news:5DAE4BD5-081B-4E56-A476-(E-Mail Removed)...
> >I inserted Call Worksheet_SelectionChange and Call
> > Worksheet_SelectionChange(ByVal Target As Range) as the first line of my
> > Command Button to check for a proper selection but get an error message
> > "Argument not Optional"
> >
> > "JLGWhiz" wrote:
> >
> >> Give this a shot.
> >>
> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >> If Target.Column = 3 And Target.Cells.Count = 1Then
> >> If Not IsEmpty(Target) And Target <> "" Then
> >> MsgBox "Has Data"
> >> Else
> >> MsgBox "No Data"
> >> End If
> >> End If
> >> End Sub
> >>
> >>
> >>
> >> "oldjay" <(E-Mail Removed)> wrote in message
> >> news:021EA369-6EF5-4787-AF5E-(E-Mail Removed)...
> >> > This code must be inserted in a sub routine so that the code doesn't
> >> > continue
> >> > if a empty cell has been selected. as written it gives an error 424
> >> > 'Object
> >> > required"
> >> >
> >> > "Wouter HM" wrote:
> >> >
> >> >> Hi oldjay
> >> >>
> >> >> You can use the worksheet event shown below:
> >> >>
> >> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >> >> ' Be sure to look at a single cell
> >> >> If Target.Cells.Count = 1 Then
> >> >> ' Check if a cell iu column C is selected
> >> >> If Target.Column = 3 Then
> >> >> ' Check id the selected cell is empty
> >> >> If IsEmpty(Target) Then
> >> >> MsgBox "On empty cell"
> >> >> End If
> >> >> End If
> >> >> End If
> >> >> End Sub
> >> >>
> >> >>
> >> >> HTH,
> >> >>
> >> >> Wouter
> >> >> .
> >> >>
> >>
> >>
> >> .
> >>

>
>
> .
>

 
Reply With Quote
 
JLGWhiz
Guest
Posts: n/a
 
      7th Mar 2010
This snippet will check the value of the selected cell and if that value =
214 then it will check cell R1 and if it is equal to or less than zero, a
message will pop up to notifty the user. If the selected cell does not equal
214, or if the cell does equal 214 but R1 is greater than zero, the user
will not receive a notice.


If Selection.Value = 214 Then
If Range("R1").Value <= 0 Then
MsgBox "Cell R1 is zero or less"
End If
Emd Of





"oldjay" <(E-Mail Removed)> wrote in message
news:992F6248-D8D3-4783-927E-(E-Mail Removed)...
> Thanks
>
> That runs so well I thought I might ask you
> for the code that will be inside a macro. If the selected cell =214 then
> check to be sure there is a value greater than zero in cell R1 if not
> error
> message
>
> "JLGWhiz" wrote:
>
>> The code should have been put in the worksheet code module if the title
>> line
>> of Private Sub Worksheet_SelectionChange() is used. Then when you select
>> a
>> cell on the worksheet, if it is in column C it will trigger the
>> procedure.
>> If you want to use a command button to run the procedure, you will need
>> it
>> written differently and the procedure to check the cells should be put in
>> the public module.
>>
>> For the command button:
>>
>> Private Sub CommandButton1_Click()
>> Call ChkColC
>> End Sub
>>
>> For the public Module1
>>
>> Sub ChkColC()
>> If ActiveCell.Column = 3 Then
>> If Not IsEmpty(ActiveCell) And ActiveCell <> "" Then
>> MsgBox "Has Data"
>> Else
>> MsgBox "No Data"
>> End If
>> End If
>> End Sub
>>
>>
>>
>>
>>
>> "oldjay" <(E-Mail Removed)> wrote in message
>> news:5DAE4BD5-081B-4E56-A476-(E-Mail Removed)...
>> >I inserted Call Worksheet_SelectionChange and Call
>> > Worksheet_SelectionChange(ByVal Target As Range) as the first line of
>> > my
>> > Command Button to check for a proper selection but get an error message
>> > "Argument not Optional"
>> >
>> > "JLGWhiz" wrote:
>> >
>> >> Give this a shot.
>> >>
>> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> >> If Target.Column = 3 And Target.Cells.Count = 1Then
>> >> If Not IsEmpty(Target) And Target <> "" Then
>> >> MsgBox "Has Data"
>> >> Else
>> >> MsgBox "No Data"
>> >> End If
>> >> End If
>> >> End Sub
>> >>
>> >>
>> >>
>> >> "oldjay" <(E-Mail Removed)> wrote in message
>> >> news:021EA369-6EF5-4787-AF5E-(E-Mail Removed)...
>> >> > This code must be inserted in a sub routine so that the code doesn't
>> >> > continue
>> >> > if a empty cell has been selected. as written it gives an error 424
>> >> > 'Object
>> >> > required"
>> >> >
>> >> > "Wouter HM" wrote:
>> >> >
>> >> >> Hi oldjay
>> >> >>
>> >> >> You can use the worksheet event shown below:
>> >> >>
>> >> >> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>> >> >> ' Be sure to look at a single cell
>> >> >> If Target.Cells.Count = 1 Then
>> >> >> ' Check if a cell iu column C is selected
>> >> >> If Target.Column = 3 Then
>> >> >> ' Check id the selected cell is empty
>> >> >> If IsEmpty(Target) Then
>> >> >> MsgBox "On empty cell"
>> >> >> End If
>> >> >> End If
>> >> >> End If
>> >> >> End Sub
>> >> >>
>> >> >>
>> >> >> HTH,
>> >> >>
>> >> >> Wouter
>> >> >> .
>> >> >>
>> >>
>> >>
>> >> .
>> >>

>>
>>
>> .
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If Then in VBA, check cell, enter data to other cell =?Utf-8?B?V2lu?= Microsoft Excel Programming 6 28th Mar 2007 12:56 AM
How do I check several sheets for data in a particular cell? =?Utf-8?B?TGVl?= Microsoft Excel Misc 0 25th Oct 2006 07:47 AM
Check part of cell for data =?Utf-8?B?TWlrZSBLLg==?= Microsoft Excel Programming 1 21st Jun 2006 11:43 PM
Check to see if cell data is within a range mwrfsu Microsoft Excel Worksheet Functions 3 22nd Aug 2005 09:03 PM
How to check cell data Jeff Armstrong Microsoft Excel Programming 1 28th Jul 2004 05:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:48 PM.