Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default If A is poplated, so must B

Hi. Prior to a macro executing, I would like to have the code check a
certain condition. If Cell A1 is not blank, then B1 is a required field.
So conceptually, look at the entire Sheet1, scan column A. For each cell in
column A, if a cell is populated, then cell B should be too. If not, Msg
Box (ideally detailing what cell triggered the Msg Box) and end the sub.

I am thinking this is a separate Sub that will run prior to the main sub.
It does not have to check the Sheet dynamically. I just can't have the Main
Sub execute with missing info. Can anyone help? Thank you!


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default If A is poplated, so must B

Use code like the following:

Dim Rng As Range
For Each Rng In ActiveSheet.UsedRange.Columns(1).Cells
If Rng.Value < "" Then
If Rng(1, 2).Value = "" Then
MsgBox "Blank cell in " & Rng(1, 2).Address
Exit Sub
End If
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steph" wrote in message
...
Hi. Prior to a macro executing, I would like to have the code
check a
certain condition. If Cell A1 is not blank, then B1 is a
required field.
So conceptually, look at the entire Sheet1, scan column A. For
each cell in
column A, if a cell is populated, then cell B should be too.
If not, Msg
Box (ideally detailing what cell triggered the Msg Box) and end
the sub.

I am thinking this is a separate Sub that will run prior to the
main sub.
It does not have to check the Sheet dynamically. I just can't
have the Main
Sub execute with missing info. Can anyone help? Thank you!




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 312
Default If A is poplated, so must B

Thanks Chip!

"Chip Pearson" wrote in message
...
Use code like the following:

Dim Rng As Range
For Each Rng In ActiveSheet.UsedRange.Columns(1).Cells
If Rng.Value < "" Then
If Rng(1, 2).Value = "" Then
MsgBox "Blank cell in " & Rng(1, 2).Address
Exit Sub
End If
End If
Next Rng


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Steph" wrote in message
...
Hi. Prior to a macro executing, I would like to have the code
check a
certain condition. If Cell A1 is not blank, then B1 is a
required field.
So conceptually, look at the entire Sheet1, scan column A. For
each cell in
column A, if a cell is populated, then cell B should be too.
If not, Msg
Box (ideally detailing what cell triggered the Msg Box) and end
the sub.

I am thinking this is a separate Sub that will run prior to the
main sub.
It does not have to check the Sheet dynamically. I just can't
have the Main
Sub execute with missing info. Can anyone help? Thank you!






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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



All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"