Find & replace issue

Scoti

New Member
Joined
Nov 8, 2020
Messages
39
Office Version
  1. 2010
Platform
  1. Windows
I'm pretty new at this and have received a lot of help through this forum but I need just a little more help with an issue I can't seem to figure out. I am running this code and it works fine other than in addition to changing the cell in column B of the found row, it also changes the value in cell B1. In that cell I have a name of "Department" which should not be changed. The only value that should be changed is in the cell 2 columns to the left of the found cell value. Can anyone tell me what I have wrong here?

Here is my code:



VBA Code:
Private Sub CommandButton1_Click()

Application.Calculation = xlCalculationManual

Application.ScreenUpdating = False

Application.DisplayStatusBar = False

Application.EnableEvents = False

ActiveSheet.DisplayPageBreaks = False

Dim FindString As String

Dim rng As Range

Dim d1 As Double

Dim d2 As Double

Set Sheet = Sheets("Manual_Dashboard")

d1 = Range("N12").Value

d2 = Range("N14").Value

For Each Cell In Range("D4:D43")

FindString = Cell.Value

With Sheets("Man_Received").Range("D:D")

Set rng = .Find(What:=FindString, _

After:=.Cells(.Cells.Count), _

LookIn:=xlValues, _

LookAt:=xlWhole, _

SearchOrder:=xlByRows, _

SearchDirection:=xlDown, _

MatchCase:=False

If Not rng Is Nothing Then

Application.Goto rng, True

If CheckBox1.Value = False Then

rng.Offset(0, -2).Value = "Manual Digestion-Acid Consumption"

Range("N12") = d1 + Range("D3").Value

Else

rng.Offset(0, -2).Value = "Manual Digestion-Acid Consumption-Retest"

Range("N14") = d2 + Range("D3").Value

End If

End If

End With

Next

With Sheets("Manual_Dashboard")

Range("D4:D43").ClearContents

End With

Sheet.Activate

Application.Calculation = xlCalculationAutomatic

Application.ScreenUpdating = True

Application.DisplayStatusBar = True

Application.EnableEvents = True

ActiveSheet.DisplayPageBreaks = True

End Sub
 
Last edited by a moderator:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Find & replace Code - OzGrid Free Excel/VBA Help Forum
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,913
Members
449,093
Latest member
dbomb1414

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