Worksheet_Change - Targeting multiple cells simultaneously

Snotty

VBA beginner here.

I have project where I have specified input cells for the user. When one of these input cells is changed, it needs to run a few lines of code that are specific to only that one cell. If the user clears the contents of the cell, I want the code to replace the blank cell with the value "0".

The code below simulates what I am trying to achieve. It is written in the same form as my project but is more succinct.

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Column = 1 And Target.Row = 1 Then
    Range("B1").Value = "Changed 1"  'Just something specific to this cell. Not important
    If IsEmpty(Sheet1.Range("A1")) Then Sheet1.Range("A1").Value = 0
End If

If Target.Column = 1 And Target.Row = 2 Then
    Range("B2").Value = "Changed 2" 'Just something specific to this cell. Not important
    If IsEmpty(Sheet1.Range("A2")) Then Sheet1.Range("A2").Value = 0
End If

If Target.Column = 1 And Target.Row = 3 Then
    Range("B3").Value = "Changed 3" 'Just something specific to this cell. Not important
    If IsEmpty(Sheet1.Range("A3")) Then Sheet1.Range("A3").Value = 0
End If

End Sub

Everything above works fine when the changes are performed on single cells. If the user selects all the cells and presses the delete key, it only runs the code for the first cell. I want it to run for all the selected (deleted) cells.

Any advice on how to simultaneously run the Worksheet_Change across multiple cells?

Thanks

Tim Williams
Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Application.Intersect(Target, Cells(1, 1)) Is Nothing Then
        Range("B1").Value = "Changed 1"  'Just something specific to this cell. Not important
        If IsEmpty(Sheet1.Range("A1")) Then Sheet1.Range("A1").Value = 0
    End If

    If Not Application.Intersect(Target, Cells(1, 2)) Is Nothing Then
        Range("B2").Value = "Changed 2" 'Just something specific to this cell. Not important
        If IsEmpty(Sheet1.Range("A2")) Then Sheet1.Range("A2").Value = 0
    End If

    If Not Application.Intersect(Target, Cells(1, 3)) Then
        Range("B3").Value = "Changed 3" 'Just something specific to this cell. Not important
        If IsEmpty(Sheet1.Range("A3")) Then Sheet1.Range("A3").Value = 0
    End If

End Sub

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Worksheet_Change Macro - Changing multiple cells

From Dev

VBA worksheet change with multiple cells

From Dev

Is there a way to run multiple cells simultaneously in IPython notebook?

From Dev

Combining multiple macros (worksheet_change)

From Dev

Combining multiple Worksheet_Change macros

From Dev

Change multiple named cells and ranges in a worksheet at once

From Dev

Worksheet_change macro running multiple times in excel 2007

From Dev

VBA Trying to make WorkSheet_Change work on multiple sheets but not all

From Dev

Multiple worksheet_change with same macro with different reference cell

From Dev

Limit characters of cells to certain bytes in Worksheet_Change applicable for all languages

From Dev

Don't run Sub Worksheet_Change(ByVal Target As Range) after all cells in the worksheet has been cleared

From Dev

Add multiple hyperlinks to multiple cells in worksheet

From Dev

Targeting multiple Windows versions

From Dev

Targeting multiple choice questions

From Dev

Change style of multiple element groups simultaneously on hover using Angular

From Dev

Sort multiple lists simultaneously

From Dev

simultaneously scroll multiple elements

From Dev

Running multiple commands simultaneously

From Dev

PHP Multiple Selects Simultaneously?

From Dev

creating multiple subplots simultaneously

From Dev

Pressing multiple keys simultaneously

From Dev

simultaneously scroll multiple elements

From Dev

Kendo grid change multiple selected cells value

From Dev

Kendo grid change multiple selected cells value

From Dev

Change border color of multiple cells in Excel 2010?

From Dev

Excel Macro: If cell = "x", copy multiple cells from other worksheet

From Dev

Multiple Timed events running simultaneously

From Dev

Showing multiple Tooltips in highcharts simultaneously

From Dev

Matcher on multiple properties simultaneously on a Collection

Related Related

  1. 1

    Worksheet_Change Macro - Changing multiple cells

  2. 2

    VBA worksheet change with multiple cells

  3. 3

    Is there a way to run multiple cells simultaneously in IPython notebook?

  4. 4

    Combining multiple macros (worksheet_change)

  5. 5

    Combining multiple Worksheet_Change macros

  6. 6

    Change multiple named cells and ranges in a worksheet at once

  7. 7

    Worksheet_change macro running multiple times in excel 2007

  8. 8

    VBA Trying to make WorkSheet_Change work on multiple sheets but not all

  9. 9

    Multiple worksheet_change with same macro with different reference cell

  10. 10

    Limit characters of cells to certain bytes in Worksheet_Change applicable for all languages

  11. 11

    Don't run Sub Worksheet_Change(ByVal Target As Range) after all cells in the worksheet has been cleared

  12. 12

    Add multiple hyperlinks to multiple cells in worksheet

  13. 13

    Targeting multiple Windows versions

  14. 14

    Targeting multiple choice questions

  15. 15

    Change style of multiple element groups simultaneously on hover using Angular

  16. 16

    Sort multiple lists simultaneously

  17. 17

    simultaneously scroll multiple elements

  18. 18

    Running multiple commands simultaneously

  19. 19

    PHP Multiple Selects Simultaneously?

  20. 20

    creating multiple subplots simultaneously

  21. 21

    Pressing multiple keys simultaneously

  22. 22

    simultaneously scroll multiple elements

  23. 23

    Kendo grid change multiple selected cells value

  24. 24

    Kendo grid change multiple selected cells value

  25. 25

    Change border color of multiple cells in Excel 2010?

  26. 26

    Excel Macro: If cell = "x", copy multiple cells from other worksheet

  27. 27

    Multiple Timed events running simultaneously

  28. 28

    Showing multiple Tooltips in highcharts simultaneously

  29. 29

    Matcher on multiple properties simultaneously on a Collection

HotTag

Archive