hi-liting one cell changes another cell

juan1

New Member
Joined
May 17, 2017
Messages
46
I would like to have cell C50 (presently shows the letter A in it, representing a dimension) to show the value of another cell that I click from (would be from locked cells F4:Z4), not actually change it.

I would then do this for other typical areas for other dimensions.

thanks for any help
Juan
 
Alternatively, you could suppress the "Save" warning like this:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)

'   Select appropriate sheet
    Sheets("Sheet1").Activate

'   Unprotect sheet
    ActiveSheet.Unprotect Password:="pass"

'   Update C50
    Range("C50") = "A"
    
'   Re-protect sheet
    ActiveSheet.Protect Password:="pass"
    
'   Save workbook
    Application.DisplayAlerts = False
    ActiveWorkbook.Save
    Application.DisplayAlerts = True
    
End Sub
Though I kind of like the Workbook_Open way better.
 
Upvote 0

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
you are correct the simple workbook open is easy and just will reset everything no matter how I choose to end.

thanks for all the help, I will continue my project and see if I come up with any more issues as I expand.
Juan
 
Upvote 0
ok doing my official file now, not the example you helped me with. The following works, but when I try to add more I cant figure out how to add the 2nd option.
This is the 2nd option: below this is what works so far.

Set isect = Intersect(Target, Range("W35:AK36"))

If isect Is Nothing Then
Range("H67") = "a1 or a2"
Else
Range("H67") = ActiveCell


THIS WORKS SO FAR!

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim isect As Range

' Unprotect sheet
ActiveSheet.Unprotect Password:="jlp"

Set isect = Intersect(Target, Range("W40:AK40"))

If isect Is Nothing Then
Range("H77") = "d"
Else
Range("H77") = ActiveCell

End If


' Re-protect sheet
ActiveSheet.Protect Password:="jlp"

End Sub
 
Upvote 0
We now have two cells being updated, H67 and H77.

So what should happen in the following cases:
- If a cell in W40:AK40 gets selected, H77 gets updated. What should happen to H67 in this case?
- If a cell in W35:AK36 gets selected, H67 gets updated. What should happen to H77 in this case?
- If a cell outside both those ranges gets selected, what should happen to both H67 and H77 in that case?
 
Upvote 0
Perhaps this is what you are looking for:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    Dim isect As Range
    Dim isect2 As Range

'   Unprotect sheet
    ActiveSheet.Unprotect Password:="jlp"

    Set isect = Intersect(ActiveCell, Range("W40:AK40"))
    Set isect2 = Intersect(ActiveCell, Range("W35:AK36"))

    If (isect Is Nothing) And (isect2 Is Nothing) Then
        Range("H67") = "a1 or a2"
        Range("H77") = "d"
    Else
        If Not (isect Is Nothing) And (isect2 Is Nothing) Then
            Range("H77") = ActiveCell
            Range("H67") = "a1 or a2"
        Else
            If (isect Is Nothing) And Not (isect2 Is Nothing) Then
                Range("H67") = ActiveCell
                Range("H77") = "d"
            End If
        End If
    End If
        
'   Re-protect sheet
    ActiveSheet.Protect Password:="jlp"

End Sub
 
Upvote 0
This works but, thought I could expand. What happens when I want to added more range options?
 
Upvote 0
Just how many more ranges are we talking here?

When doing this sort of coding, it is helpful to know exactly where you want to go. The danger in oversimplifying questions here, is that you might get an answer that is difficult to expand upon, since it addresses the question you asked (and not the real problem you are working on).
 
Upvote 0
OK, here is a version where you can add as many ranges as you like.
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

'   Unprotect sheet
    ActiveSheet.Unprotect Password:="jlp"
    
'   Set all initial "default" values
    Range("H67") = "a1 or a2"
    Range("H77") = "d"
    Range("H87") = "e"
    
'   Check first range
    If Not Intersect(ActiveCell, Range("W40:AK40")) Is Nothing Then
        Range("H77") = ActiveCell
        GoTo end_jump
    End If
    
'   Check second range
    If Not Intersect(ActiveCell, Range("W35:AK36")) Is Nothing Then
        Range("H67") = ActiveCell
        GoTo end_jump
    End If

'   Check third range
    If Not Intersect(ActiveCell, Range("W32:AK33")) Is Nothing Then
        Range("H87") = ActiveCell
        GoTo end_jump
    End If
    
end_jump:
'   Re-protect sheet
    ActiveSheet.Protect Password:="jlp"

End Sub
I did it for three ranges, but you can keep adding more. Just add new blocks under each section, and be sure to add the new initial default values at the top.
 
Upvote 0

Forum statistics

Threads
1,224,835
Messages
6,181,247
Members
453,026
Latest member
cknader

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