vba question

A1058

New Member
Joined
Sep 13, 2006
Messages
46
hello guys im wondering if someone can help
id like to with vba have it look at cells A2:A31 and A37:A51, and if these cells <> "" then S2:S31 and S37:S51 should also have a value. so whatever cells in column A in the range listed have values the corresponding cells in column S should also have a value and IF they do not have a value in column S i need sheet printing to be disabled and to popup a msgbox saying Column S values not entered . once column S values are all ok then reenable sheet printing

thans a lot guys :)
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hello A1058,
Try something like this in the ThisWorkbook module.
(Will only test if it's sheet2 that's trying to be printed. Change that to suit.)
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet2" Then
  Dim Rng As Range, c As Range
  Set Rng = Range("A2:A31", "A37:A51")
  For Each c In Rng
    If Not IsEmpty(c) And IsEmpty(c(, 19)) Then
      Cancel = True
      MsgBox ("There is a value in " & c.Address(0, 0) & " with no value in " & c(, 19).Address(0, 0)), , "Missing Data in Column S"
      Exit Sub
  End If
  Next c
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,821
Messages
6,121,759
Members
449,048
Latest member
excelknuckles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top