VBA find a code and replace the value

jevi

Active Member
Joined
Apr 13, 2010
Messages
339
Office Version
  1. 2016
Platform
  1. Windows
Hi All,

I have registered this macro but is not working well. I would like that check the data in column A (might be everyday different rows of data) and if you find the code 100000 then in the column it should write the code 90...so in this case it did find the code 100000 in the row A306 and A307 and it changed the data in row Q306 and Q307 but the problem is that this code 100000 is not everyday in the same rows, sometimes it might be in two or 3 rows. Any help how to achieve it?

VBA Code:
Columns("A:A").Select
    Selection.Find(What:="100000", After:=ActiveCell, LookIn:=xlFormulas2, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Selection.FindNext(After:=ActiveCell).Activate
    Range("Q306:Q307").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "990"
    Range("Q307").Select
    ActiveCell.FormulaR1C1 = "990"
    Range("Q307").Select

Thank you
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Is that code on it's own in the cell & is it a number or text?
 
Upvote 0
Is that code on it's own in the cell & is it a number or text?
Hi Pluff,

The code it is in its own and it looks like a number but if formatted as General.

thnx
 
Upvote 0
If you use
Excel Formula:
=isnumber(A2)
in another cell what does it say. Change the A2 to a cell that contains 100000
 
Upvote 0
Ok, how about
VBA Code:
Sub jevi()
   With Range("A2", Range("A" & rows.count).End(xlUp))
      .Offset(, 16).Value = Evaluate(Replace("if(" & .Address & "=100000,990,if(@="""","""",@))", "@", .Offset(, 16).Address))
   End With
End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
Sub jevi()
   With Range("A2", Range("A" & rows.count).End(xlUp))
      .Offset(, 16).Value = Evaluate(Replace("if(" & .Address & "=100000,990,if(@="""","""",@))", "@", .Offset(, 16).Address))
   End With
End Sub
It worked so great :). Thank youuuuuu so much as it is a daily task.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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