Macro should have changed cell value but did not

sts8500man

Board Regular
Joined
Jul 12, 2012
Messages
74
Office Version
  1. 365
Platform
  1. Windows
A
B
C
D
1
381.611
$2,224.79
$2,241.45
2
381.611
$2,232.42
3
381.611
$2,232.42
4
379.265
$2,241.45
5
379.265
$2,241.45
6
379.265
$2,237.66
7
379.265
$2,237.66
8
379.265
$2,241.45
9
$0.00
10
I have the following macro to act on the above data:

If Range("B1").Value <> Range("B2").Value Then
Range("D1").Value = Range("C1").Value
End If
End Sub

A new row 1 is added periodically by "insertion" - move rows down. The objective is for the value in cell D2 to remain the same as long as B1 and B2 are equal but to take on the value of C1 when an added new row causes B1 and B2 to no longer be equal. The macro worked just fine when the values in B1 changed from 0 to 379.265, the proper value of $2241.45 being displayed in D2 and remained that value while the next several lines were added. However, when the row was added that caused the value of B1 to change from 379.265 to 381.611, the value in D1 did not change. It remained $2241.45. It should have changed to $2224.79. Can someone tell me why the macro worked properly when B1 changed from 0 to 379.265 but did not work when it changed from 379.265 to 381.611? Please offer a suggestion to correct the problem.

<tbody>
</tbody>
 
Last edited:

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

sts8500man

Board Regular
Joined
Jul 12, 2012
Messages
74
Office Version
  1. 365
Platform
  1. Windows
Replying to my own thread - forget this - I found the problem - had to do with how I was handling my test worksheet; the VBA code worked once I determined how to use the test worksheet correctly.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,469
Messages
5,596,316
Members
414,053
Latest member
Dual Showman

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
Top