I'm writing a macro on excel.
Every time a value is typed in a specific range, if the calculated result is too low, I need a message box to appear saying ""Sample volume too low! Please increase total volume." as well as printing the range in which it was typed.
The below code works for just printing the message, but I need to know if I can also print the range.
Thank you
Private Sub Worksheet_Change(ByVal Target As Range)
Dim r1 As Range, r2 As Range, MultipleRange As Range
Set r1 = Range("I17:I20")
Set r2 = Range("Q17:Q20")
Set MultipleRange = Union(r1, r2)
If Not Intersect(Target, MultipleRange) Is Nothing Then
If Range("G17") < 5 Then
MsgBox "Sample volume too low!Please increase total volume."
End If
If Range("G18") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
If Range("G19") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
If Range("G20") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
If Range("O17") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
If Range("O18") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
If Range("O19") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
If Range("O20") < 5 Then
MsgBox "Sample volume too low! Please increase total volume."
End If
End If
End Sub