Using vba code to clear a cell value immediately after use

bcselect

Board Regular
Joined
May 13, 2021
Messages
80
Office Version
  1. 365
Platform
  1. Windows
This is test code that demonstrates what I need to do. It looks for an "M" and when found, copies and pastes the 2 cells adjacent.
I need the code to IMMEDIATELY erase the "M" once it is done. I can't seem to make that happen. Any help appreciated.

VBA Code:
Sub Find()
Application.ScreenUpdating = False
Dim SearchRange As Range
Dim FindCell As Range
Dim Check As Boolean
Dim LastRow As Long
Dim ws As Worksheet
Dim ws2 As Worksheet
Dim FindCounter As Long

Set ws = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Sheets("Sheet1").Select
LastRow = ws.Cells(Rows.Count, "F").End(xlUp).Row
Set SearchRange = Range("F1:F" & LastRow)
FindCounter = 0
ws2.Range("H10:I30").Clear
For Each FindCell In SearchRange
    If FindCell.Value = "M" Then
        FindCounter = FindCounter + 1
        FindCell.Offset(0, 1).Resize(, 2).Copy

 ws2.Range("H10").Insert
      Application.CutCopyMode = False
    End If
Next

MsgBox "Succes!" & vbNewLine & vbNewLine & "This many cells were found: " & FindCounter
Application.ScreenUpdating = True
Sheets("Sheet2").Select
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
How about adding this line
Rich (BB code):
 ws2.Range("H10").Insert
      Application.CutCopyMode = False
      FindCell.Value = ""
    End If
 
Upvote 0
You should be able to set the FindCell.Value to "" when you test and find an "M".

Is this what you were looking for?

VBA Code:
If FindCell.Value = "M" Then
        FindCell.Value = ""
 
Upvote 0
Solution
You should be able to set the FindCell.Value to "" when you test and find an "M".

Is this what you were looking for?

VBA Code:
If FindCell.Value = "M" Then
        FindCell.Value = ""
Thanks! Perfect
 
Upvote 0
Did you try the other suggestions. ;)
 
Upvote 0

Forum statistics

Threads
1,215,046
Messages
6,122,855
Members
449,096
Latest member
Erald

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