Macro should have changed cell value but did not

sts8500man

Board Regular
Joined
Jul 12, 2012
Messages
77
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:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
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.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,716
Members
448,985
Latest member
chocbudda

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