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
 
It should have no effect on any other sheet.
Also one last thing. Now that i have save it as xlsm, everytime i open the file i got a Security warning in the yellow banner says that the macros have been disabled and i have to select "enable content" in order all this to work. Is there anything i can do to be enabled by default?
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Also one last thing. Now that i have save it as xlsm, everytime i open the file i got a Security warning in the yellow banner says that the macros have been disabled and i have to select "enable content" in order all this to work. Is there anything i can do to be enabled by default?
Now i noticed that only row 7 is affected. So if i would like to use this in my table with a lot of rows do i need to replace the B7 and Q7 inside the code with B7:B50 for exmple? as also Q7:Q50? And if yes what will happen if i add more columns or rows in my table? will renew the code automatecally including the new rows or do i have to do it manually?
 
Upvote 0
Dear @mumps please ignore the message about the security warning. It was only showed up the first couple of times i opened the file.
Just check my other message:
Now i noticed that only row 7 is affected. So if i would like to use this in my table with a lot of rows do i need to replace the B7 and Q7 inside the code with B7:B50 for exmple? as also Q7:Q50? And if yes what will happen if i add more columns or rows in my table? will renew the code automatecally including the new rows or do i have to do it manually?
I have try it but propably it's not the right way because nothing worked as it should. So what do i have to do to affect my whole table (rows)?
 
Upvote 0
This version will work with all rows starting at row 7. It also assumes that you will have a formula in all applicable rows in column Q.
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
    Else
        Range("Q" & Target.Row).Formula = "=ROUND((A" & Target.Row & "*$D$1),0)"
    End If
End Sub
 
Upvote 0
This version will work with all rows starting at row 7. It also assumes that you will have a formula in all applicable rows in column Q.
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
    Else
        Range("Q" & Target.Row).Formula = "=ROUND((A" & Target.Row & "*$D$1),0)"
    End If
End Sub
[/CODEOhhhh
[/QUOTE]
Ohhhh.... You are great!!! I just notice one thing... i have also another column with a formula that has to be locked like Q column. Is column T. The formula in column T is =(K7-($D$3*$D$2))/$D$1
Actualy the column Q refers to kg and column T refers to money. So when i choose the drop down from B it has to lock both cells Q and T.
Sorry if i am obtrusive but you are the only one who help me and i have no idea to do all that by self.
 
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("Q" & Target.Row).Value = Range("Q" & Target.Row).Value
        Range("T" & Target.Row).Value = Range("T" & Target.Row).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
 
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("Q" & Target.Row).Value = Range("Q" & Target.Row).Value
        Range("T" & Target.Row).Value = Range("T" & Target.Row).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
You are fantastic!!!!!
So... i suppose that if in the future i need to add some more columns in my table i just need to change the Q and T columns letter of the code with the new ones right? Of course as also the letters in the formulas if they are affected. Am i right?
 
Upvote 0
That is correct. Just follow the same code pattern.
 
Upvote 1
That is correct. Just follow the same code pattern.
You have helped me to solve an issue i was strunggling to find a way for weeks now. And acctualy you did it better than i could imagine.
Thank you so much for your precious help and the time and effort you spent for me.
 
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("Q" & Target.Row).Value = Range("Q" & Target.Row).Value
        Range("T" & Target.Row).Value = Range("T" & Target.Row).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
Dear @mumps i just notice an issue at column T. Although i have set it as currency cell with 4 demicals, when i choose the drop down list in order to lock it, it makes a rounding in 2 demicals although it showing 4 demicals. For example before "locking" i have a value 1,0488 and after locking it makes it 1,0500. I check the cell format after "locking" and it is still currency cell with 4 demicals.
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,138
Members
453,021
Latest member
Justyna P

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