How can this be edited so that if cell B5 is empty a msgbox comes up if not the macro follows through?
Many ThanksCode:Private Sub Worksheet_Change(ByVal Target As Range) Sheets("Headed Paper").Range("N1").Value = Sheets(ActiveSheet.Name).Range("A2").Value Sheets("Headed Paper").Range("O1").Value = Sheets(ActiveSheet.Name).Range("A3").Value Dim shSource As Worksheet, shDestination As Worksheet, iR As Long, i As Byte Set shSource = ActiveSheet Set shDestination = Sheets("Invoice Template") ' =Sheet4 If Target.Count > 1 Then Exit Sub If (Not Intersect(Target, shSource.Range("J5:J500")) Is Nothing) And Target.Cells.Count = 1 Then If UCase(Target.Value) = "Y" Then Worksheets("Invoice Template").Visible = True Dim aso(), aco() aso = Array("A", "B", "C", "D", "G", "F", "H", "I") aco = Array("B14", "B16", "F16", "D35", "D36", "D37", "D38", "D39") iR = Target.Row For i = 0 To UBound(aso) Range("J" & iR).FormulaR1C1 = "DONE" shDestination.Range(aco(i)).Value = shSource.Range(aso(i) & iR).Value Next With Sheets("Invoice Template") .Range("N1").Value = Sheets(ActiveSheet.Name).Range("A2").Value .Range("O1").Value = Sheets(ActiveSheet.Name).Range("A3").Value End With Range("o3").Value = ("J" & iR) shDestination.Protect shDestination.Select Sheet1.Visible = False Sheet2.Visible = False Sheet5.Visible = False End If End If Application.EnableEvents = True End Sub
Start of like this...
Code:Private Sub Worksheet_Change(ByVal Target As Range) If IsEmpty(Range("B5")) Then MsgBox "Cell B5 is not supposed to be empty..." Exit Sub End If ....continue your macro
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
As the first line(s):
Code:If Range("B5").Value = "" Then MsgBox "B5 is blank" Exit Sub End If
If you find the response helpful please click the scales in the blue bar above and rate it
If you don't like the response, don't bother with the scales, they are not for you
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks