VBA code to show message box popup if the formula in the target column exceeds a certain value

Shaun Crossley

I found this code on this site for a particular cell

Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A1") > 0.5 Then
    MsgBox "Discount too high"
End If
End Sub

But I was wondering if it is possible to make this work for an entire column rather than one particular cell?

Gary's Student

Try this for your event code:

Private Sub Worksheet_Calculate()
    Dim rr As Range, r As Range
    Set rr = Range("A:A").Cells.SpecialCells(xlCellTypeFormulas)
    For Each r In rr
        If r.Value > 0.5 Then
            MsgBox "Discount too high"
        End If
    Next r
End Sub

EDIT#1:

if you want to restrict the message to a single row, then remove the first sub and replace it with:

Private Sub Worksheet_Change(ByVal Target As Range)
    rt = Target.Row
    If Range("A" & rt) > 0.5 Then
        MsgBox "Discount too high"
    End If
End Sub

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Message box show output of command

분류에서Dev

Confirm message box return error value

분류에서Dev

Show value (price) of certain package with javascript

분류에서Dev

Deleting rows based on cell value in a certain column

분류에서Dev

Find out whether elements are unique within a certain range without having to program a macro in VBA: Is there a formula that can do that?

분류에서Dev

How to show a text box if value in tablix is empty in RDLC report

분류에서Dev

Excel VBA code for replacing all "." by "," in a column

분류에서Dev

Filling Data with VBA Code by User Form in Certain Row

분류에서Dev

Excel VBA: how to store combo box current value to cell

분류에서Dev

Excel VBA How to append column of value to array?

분류에서Dev

Enter a formula into cells with VBA

분류에서Dev

Monitor a certain folder/file and send notification when it exceeds a certain size

분류에서Dev

Excel VBA: How to return value without making a function that is available in the formula bar

분류에서Dev

Message box in CATScript

분류에서Dev

Swift Message Box

분류에서Dev

How to show a column with the value Zero in Bar chart in Highcharts?

분류에서Dev

Excel Formula To Get First Non-Zero Value in Row and Return Column Header

분류에서Dev

Assign formula to cell using VBA?

분류에서Dev

Excel - VBA - formula error 1004 -

분류에서Dev

Pointer value exceeds available memory? How?

분류에서Dev

Copying certain columns VBA

분류에서Dev

Formula to extract certain character positions in a string

분류에서Dev

Disable background when automatically popup box displayed

분류에서Dev

How do I loop through certain records, check a query, and conditionally assign field value using VBA?

분류에서Dev

Excel spreadsheet formula to sum a column

분류에서Dev

Message box closing form erradically

분류에서Dev

Remove column from column control popup menu

분류에서Dev

Need to target certain number of characters with css

분류에서Dev

Obiee Formula to show TIMESTAMP only hours format

Related 관련 기사

  1. 1

    Message box show output of command

  2. 2

    Confirm message box return error value

  3. 3

    Show value (price) of certain package with javascript

  4. 4

    Deleting rows based on cell value in a certain column

  5. 5

    Find out whether elements are unique within a certain range without having to program a macro in VBA: Is there a formula that can do that?

  6. 6

    How to show a text box if value in tablix is empty in RDLC report

  7. 7

    Excel VBA code for replacing all "." by "," in a column

  8. 8

    Filling Data with VBA Code by User Form in Certain Row

  9. 9

    Excel VBA: how to store combo box current value to cell

  10. 10

    Excel VBA How to append column of value to array?

  11. 11

    Enter a formula into cells with VBA

  12. 12

    Monitor a certain folder/file and send notification when it exceeds a certain size

  13. 13

    Excel VBA: How to return value without making a function that is available in the formula bar

  14. 14

    Message box in CATScript

  15. 15

    Swift Message Box

  16. 16

    How to show a column with the value Zero in Bar chart in Highcharts?

  17. 17

    Excel Formula To Get First Non-Zero Value in Row and Return Column Header

  18. 18

    Assign formula to cell using VBA?

  19. 19

    Excel - VBA - formula error 1004 -

  20. 20

    Pointer value exceeds available memory? How?

  21. 21

    Copying certain columns VBA

  22. 22

    Formula to extract certain character positions in a string

  23. 23

    Disable background when automatically popup box displayed

  24. 24

    How do I loop through certain records, check a query, and conditionally assign field value using VBA?

  25. 25

    Excel spreadsheet formula to sum a column

  26. 26

    Message box closing form erradically

  27. 27

    Remove column from column control popup menu

  28. 28

    Need to target certain number of characters with css

  29. 29

    Obiee Formula to show TIMESTAMP only hours format

뜨겁다태그

보관