How to Save cell selections after alternate dropdown selection

Crystal_Wagner

New Member
Joined
Oct 16, 2024
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Good morning,

I am newish to excel and hoping for some assistance.

I am looking for a way to save the data selections made in certain cells, to refer back to after a different dropdown option in cell b2 is made. I will try to explain as best I can.

I want to be able to highlight cells in the proficient columns, that will save to that option chosing in b2.
I have written a macro that will clear the contents once i choose a different option in b2. However when i go back to a certain name, the previous selected cell options are not saved. i want to be able to go back and see options/cells highlighted that are associated with the different users in cell b2.
 

Attachments

  • skillgap.PNG
    skillgap.PNG
    32.8 KB · Views: 4
  • macro.PNG
    macro.PNG
    11.4 KB · Views: 5

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Create a separate sheet to store highlighted cells' selection for each option in B2. Then adjust your macro to save the selected cell values before clearing them when a new option is chosen in B2

This is an outline of macro logic:

When new option is selected in B2, save current cell selections in the separately created sheet.
When switching back to a previously selected option in B2, retrieve and reapply saved selections.

VBA Code:
Sub SaveSelections()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("SavedSelections")

    ' Save the current selection when B2 changes
    Dim currentOption As String
    currentOption = Range("B2").Value

    ' Clear old data and save new data

    ws.Cells.Clear
    ws.Range("A1").Value = currentOption
    ws.Range("B1").Value = Selection.Address ' Save selected cells' address

End Sub

Sub RestoreSelections()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("SavedSelections")
   
    ' Retrieve the selection when B2 changes back
    Dim savedOption As String
    savedOption = ws.Range("A1").Value
   
    If Range("B2").Value = savedOption Then
        Range(ws.Range("B1").Value).Select ' Reapply saved selections
    End If
End Sub
 
Upvote 0
Create a separate sheet to store highlighted cells' selection for each option in B2. Then adjust your macro to save the selected cell values before clearing them when a new option is chosen in B2

This is an outline of macro logic:

When new option is selected in B2, save current cell selections in the separately created sheet.
When switching back to a previously selected option in B2, retrieve and reapply saved selections.

VBA Code:
Sub SaveSelections()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("SavedSelections")

    ' Save the current selection when B2 changes
    Dim currentOption As String
    currentOption = Range("B2").Value

    ' Clear old data and save new data

    ws.Cells.Clear
    ws.Range("A1").Value = currentOption
    ws.Range("B1").Value = Selection.Address ' Save selected cells' address

End Sub

Sub RestoreSelections()
    Dim ws As Worksheet
    Set ws = ThisWorkbook.Sheets("SavedSelections")
  
    ' Retrieve the selection when B2 changes back
    Dim savedOption As String
    savedOption = ws.Range("A1").Value
  
    If Range("B2").Value = savedOption Then
        Range(ws.Range("B1").Value).Select ' Reapply saved selections
    End If
End Sub
Would this code need to be pasted into the current worksheet im in?
Or the newly created worksheet?
 
Upvote 0

Forum statistics

Threads
1,224,814
Messages
6,181,130
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