Code not working - what is wrong.

Brutusar

Board Regular
Joined
Nov 23, 2019
Messages
166
Office Version
  1. 365
Platform
  1. Windows
Hi, I am using the code below to start a different Sub when the value of cell A1 in the active sheet is changed. However, the code is not working, meaning nothing is happening. The sub that is supposed to be started when the value is changed is working fine when run directly. I can't find my mistake in the code, but it must be something?


VBA Code:
 Sub Worksheet_Change(ByVal Target As Range)

    If Target.Address = "$A$1" Then
    
        Call CopyAndAppendRange
    End If
    
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
We would need to see what this script is supposed to do.
CopyAndAppendRange
 
Upvote 0
No, still not running. It is possible it can be a setting in my Excel?
 
Upvote 0
No, still not running. It is possible it can be a setting in my Excel?
This is the "full code" after changing "If Target.Address = "$A$1" Then" to "If Not Intersect(Range("A1"), Target) Is Nothing Then"

VBA Code:
 Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Range("A1"), Target) Is Nothing Then
   
        Call CopyAndAppendRange
       
    End If
   
End Sub


Sub CopyAndAppendRange()

   Dim wsCopy As Worksheet
   Dim wsAppend As Worksheet
 
   Set wsCopy = ActiveSheet
   Set wsAppend = Sheets("Regular")
 
   wsCopy.Range("A1:H1").Copy
   wsAppend.Cells(Rows.Count, "A").End(xlUp).Offset(1).PasteSpecial xlPasteValues
 
   Application.CutCopyMode = False
   Application.ScreenUpdating = True
  
End Sub
 
Upvote 0
What is causing the value in cell A1 to change? Is it by data entry of some kind, or is there a formula in that cell?
 
Upvote 0
There is no formulas in cell A1, just a plain text string.
 
Upvote 0
Do you have the Worksheet_Change code above pasted in the correct sheet module?
 
Upvote 0

Forum statistics

Threads
1,215,079
Messages
6,122,998
Members
449,092
Latest member
masterms

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