VBA - Auto change value in Table

KowieT

New Member
Joined
Feb 8, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,
I've got a table imported from SQL. The value in Column A to end of the range must change when you manualy enter a value in the corresponding row in Column B.
The new value for Column A is calculated in Column C.

I'm using this code in VBA, it seems to work fine till you get to row 54 then multiple values starts changing in Column A
Possibly I'm defining the range incorrectly.
Any suggestions will be appreciated.


Private Sub Worksheet_Change(ByVal Target As Range)
Dim LastRow As Long
Dim i As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To LastRow
If Not Intersect(Range("B" & i), Target) Is Nothing Then
Range("A" & i).Value = Range("C" & i).Value

End If
Next i
End Sub





Price Change.xlsm
ABC
1 Value Auto Change Value Manual Change Formula to calculate what the cell in column A must change to
28.7010.008.70
310.4312.0010.43
45.226.005.22
58.7010.008.70
617.3920.0017.39
726.0930.0026.09
886.96100.0086.96
98.7010.008.70
1052.175.004.35
118.7010.008.70
1286 956.521.000.87
134.355.004.35
148.7010.008.70
1517.3920.0017.39
1643.4810.008.70
174.355.004.35
1817.3920.0017.39
194.355.004.35
204.355.004.35
214.355.004.35
224.355.004.35
234.355.004.35
248.7010.008.70
25173.91200.00173.91
2626.0930.0026.09
2726.0930.0026.09
28434.78500.00434.78
2926.0930.0026.09
30260.87300.00260.87
3126.0930.0026.09
3226.0930.0026.09
3326.0930.0026.09
3426.0930.0026.09
3526.0930.0026.09
3627.0937.9533.00
3743.4850.0043.48
3826.0930.0026.09
398.7010.008.70
4017.3920.0017.39
4143.4850.0043.48
428.7010.008.70
439.7046.0040.00
4410.7047.1541.00
4517.3920.0017.39
4643.4850.0043.48
4743.4850.0043.48
4844.4851.7545.00
4945.4852.9046.00
5052.1760.0052.17
5143.4850.0043.48
5244.4856.3549.00
5343.4850.0043.48
5478.2690.0078.26
5543.4850.0043.48
5644.4860.9553.00
5745.4862.1054.00
5846.4863.2555.00
5947.4864.4056.00
Sheet1
Cell Formulas
RangeFormula
A36,A56:A59,A52,A48:A49,A43:A44A36=+A35+1
C2:C59C2=+B2*100/115
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
You should always disable events while making changes from a change event, to avoid recursion:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
on error goto clean_up
Dim LastRow As Long
Dim i As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
application.enableevents = false
For i = 1 To LastRow
If Not Intersect(Range("B" & i), Target) Is Nothing Then
Range("A" & i).Value = Range("C" & i).Value

End If
Next i
clean_up:
application.enableevents = true
End Sub
 
Upvote 0
You should always disable events while making changes from a change event, to avoid recursion:

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
on error goto clean_up
Dim LastRow As Long
Dim i As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
application.enableevents = false
For i = 1 To LastRow
If Not Intersect(Range("B" & i), Target) Is Nothing Then
Range("A" & i).Value = Range("C" & i).Value

End If
Next i
clean_up:
application.enableevents = true
End Sub
Thanks RoryA, working
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,770
Members
449,049
Latest member
greyangel23

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