![]() |
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! |
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! |
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! |
All times are GMT +1. The time now is 07:23 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com