VBA, Check for entry and overwrite if it does

grabrail

Board Regular
Joined
Sep 6, 2010
Messages
128
Office Version
  1. 365
Platform
  1. Windows
Hi

I have some code that monitors a cell with a drop down box, there are 3 options in the dropdown box and if 2 out of the 3 options are selected the code will create an entry elsewhere on the worksheet in a summary area.

This works perfectly. However:

There is only one entry allowed for this particular data, so if the user goes back and changes their mind on which option to use, it will create a second entry in the summary area.

What I would like to do is if an entry is made, and then changed, the second entry will overwrite or remove the first entry and only create the new entry. The code I have that works is as follows:

VBA Code:
    If Target.Value = "Excessive" Or Target.Value = "Inadequate" Then
        
                             
                Worksheets("VI Sheet").Range("A112").Select
                
                'get next blank cell
                While ActiveCell.Value <> ""
                    ActiveCell.Offset(1, 0).Range("A1").Select
                Wend
                
                'input results
                
                'box 1
                ActiveCell.FormulaR1C1 = "47"
                ActiveCell.Offset(0, 1).Range("A1").Select
                
                'box 2
                ActiveCell.FormulaR1C1 = "0"
                ActiveCell.Offset(0, 1).Range("A1").Select
                
                'box 3
                ActiveCell.FormulaR1C1 =  Target.Value & " requires attention "
                ActiveCell.Offset(0, 5).Range("A1").Select
                
                'box 4
                ActiveCell.FormulaR1C1 = "S"
                ActiveCell.Offset(0, 3).Range("A1").Select
                
                    
                'box 5
                ActiveCell.FormulaR1C1 = "FW"
                ActiveCell.Offset(0, -2).Range("A1").Select
                
                 
                ActiveCell.FormulaR1C1 = "0"
                
            End If

How can I put a check in to confirm if an entry already exists, then delete/overwrite with new entry?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
The entry could be on any one of these lines by the way

1671109092649.png
 
Upvote 0
I managed to get this working by wrapping the original code in the following code

VBA Code:
Dim rngFound as Range
With Worksheets("VI Sheet").range("C113:C141")
    Set rngFound  = .Find("requires attention", LookIn:=xlValues)
    If Not rngFound Is Nothing Then 

                            ActiveCell.FormulaR1C1 = ""
                            ActiveCell.Offset(0, -1).Range("A1").Select
                            
                            ActiveCell.FormulaR1C1 = ""
                            ActiveCell.Offset(0, -1).Range("A1").Select
                            
                            ActiveCell.FormulaR1C1 = ""
                            ActiveCell.Offset(0, 7).Range("A1").Select
                            
                            ActiveCell.FormulaR1C1 = ""
                            ActiveCell.Offset(0, 1).Range("A1").Select
                            
                            ActiveCell.FormulaR1C1 = ""
            
                           <Then above code here>
    application.got rngFound, true


    else
         <Then above code here>
    End If
End With
 
Upvote 0
Solution

Forum statistics

Threads
1,215,220
Messages
6,123,694
Members
449,117
Latest member
Aaagu

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