Permit macro-configurated cell to be overwritten manually

kanadaaa

Active Member
Joined
Dec 29, 2019
Messages
348
Office Version
  1. 365
Platform
  1. Windows
Hi, I'd like help with the following code:
VBA Code:
Public TargetCell As Range

Private Sub ComboBox1_LostFocus()
    TargetCell = ComboBox1.Value
    ComboBox1.Visible = False
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Target, Range("A1")) Is Nothing Then
        Set TargetCell = Target
        With ComboBox1
        .Height = Target.Height
        .Width = Target.Width
        .Top = Target.Top
        .Left = Target.Offset(0, 1).Left
        .Font.Size = 14
        .List = Range("C1:C10").Value
        .ListRows = 10
        .Visible = True
        .Value = ""
        .Activate
        .DropDown
        End With
    End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
    If Cells(1, 1) = "2" Then
        Cells(1, 5) = Sheets("Sheet2").Cells(2, 2).Value
    End If
End Sub
I have the numbers 1-10 as the values for Sheets(1).Range("C1:C10"), and this code works in the way that when A1 is double-clicked, the combobox shows up, so I can choose a value from those numbers.
Then, I would like E1 to be filled automatically with the value in Sheets(2).Range("B2").Value if "2" is selected, and the code works well.
But it doesn't allow me to replace the inserted value in E1 with a new value by manual input, as long as A1 on Sheet1 is filled with "2". (When E1 is clicked out after edit, it still shows the value in Sheets(2).Range("A1").
How could I make it possible to overwrite this value? Thank you.
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
This is your problem...

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Cells(1, 1) = "2" Then
        Cells(1, 5) = Sheets("Sheet2").Cells(2, 2).Value
    End If
End Sub

Everytime you edit any cell on the sheet, this will run and overwrite E1 again as long as A1 = "2"
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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