Help about an automation i want to create

damav78

New Member
Joined
Sep 29, 2024
Messages
31
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Hi, I would like your help in an issue that i cannot find a way to solve.
I have 2 cells.
The first one has a dropdown list with one option only available.
The second one is a formula cell that collects multiple data from other cells and its dynamic. It means that when i change values to other cells this cell is affected.
So what i would like to do is:
When the first cell is blank the values on second cell to change as normally do (dynamically).
If from the first cell i choose the predefined value from my dropdown list then the second cell to actually "lock" the current value that has at that moment and dosen't be affected anymore from any changes.
Thank you in advance
 
See if this works for you:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row < 7 Or Target.Column <> 2 Then Exit Sub
    If Target <> "" Then
        Range("Q" & Target.Row).Value = Range("Q" & Target.Row).Value
        Range("T" & Target.Row).Value = Round(Range("T" & Target.Row).Value, 4).Value
    Else
        Range("Q" & Target.Row).Formula = "=ROUND((A" & Target.Row & "*$D$1),0)"
        Range("T" & Target.Row).Formula = "=(K" & Target.Row & "-($D$3*$D$2))/$D$1"
    End If
End Sub
 
Last edited:
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
See if this works for you:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row < 7 Or Target.Column <> 2 Then Exit Sub
    If Target <> "" Then
        Range("Q" & Target.Row).Value = Range("Q" & Target.Row).Value
        Range("T" & Target.Row).Value = Round(Range("T" & Target.Row).Value, 4).Value
    Else
        Range("Q" & Target.Row).Formula = "=ROUND((A" & Target.Row & "*$D$1),0)"
        Range("T" & Target.Row).Formula = "=(K" & Target.Row & "-($D$3*$D$2))/$D$1"
    End If
End Sub
I got an run-time error message 424
 
Upvote 0
Which line of code is highlighted when you click "Debug"?
 
Upvote 0
It would be easier to help if you could upload a copy of your file, (de-sensitized if necessary), to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here.
 
Upvote 0
Unfortunately, that is not possible. Forum rules state that all communication must be done in the thread you posted.
 
Upvote 0
Unfortunately, that is not possible. Forum rules state that all communication must be done in the thread you posted.
Ok let me just upload only the sheet we are talking about. Because my file have some extra sheets.
 
Upvote 0
Unfortunately, that is not possible. Forum rules state that all communication must be done in the thread you posted.

Dear @mumps you will notice that i have add and delete one column. So the column Q is replaced by R, and column K is replaced by L
 
Upvote 0
Try:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Row < 7 Or Target.Column <> 2 Then Exit Sub
    If Target <> "" Then
        Range("R" & Target.Row).Value = Range("R" & Target.Row).Value
        Range("T" & Target.Row).Value = Round(Range("T" & Target.Row).Value, 4)
    Else
        Range("R" & Target.Row).Formula = "=ROUND((A" & Target.Row & "*$D$1),0)"
        Range("T" & Target.Row).Formula = "=(L" & Target.Row & "-($D$3*$D$2))/$D$1"
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,181
Members
452,615
Latest member
bogeys2birdies

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