Find and replace.

vmjan02

Well-known Member
Joined
Aug 15, 2012
Messages
1,132
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
I have this data and need to find and replace , this will be a life saver as now this takes 6 to 7 hrs for me to complete the task.
is there a way in vab that it will serach a value and replace it

only for column e were cell value is 1.
eg:- row no 13
e13 =1 then
it will find b13 from N13 to last non blank column and if found will replace it with K13.
b13 = 68248592160750700 seach this value in N19 to ZP19(last non blank cell in row 19)
b13 found in cell AA13 so now AA13 value should be replace by K13
and next

can a vba works it out this way.

sample data below.

Book2
ABCDEFGHIJKLMNOPQRSTUVWXYZAAAB
1
2
3
4
5
6
7
8PERCENTILE 99%MaxDiffd/PerAbove 50%Actual ColumnPerviousAfterPer ValNext ValAvgRemarksShort nameNE_STATEOLTShort name01/01/23, 00:0002/01/23, 00:0003/01/23, 00:0004/01/23, 00:0005/01/23, 00:0006/01/23, 00:0007/01/23, 00:0008/01/23, 00:0009/01/23, 00:0010/01/23, 00:0011/01/23, 00:00
93.71187E+123.96318E+122.51308E+116.77%0#N/A#N/A#N/ANo Change101-00_Active101-00_101-00_2.57046E+123.03085E+123.10764E+122.89118E+122.84709E+123.24747E+123.06845E+122.90603E+123.30355E+122.83128E+122.83665E+12
102.62976E+132.65269E+132.29263E+110.87%0#N/A#N/A#N/ANo Change209-00_Active209-00_209-00_2.10913E+132.00048E+132.0549E+131.92544E+131.90795E+131.81372E+132.02025E+131.80057E+131.97399E+131.78594E+131.9489E+13
112.96603E+133.05316E+138.71317E+112.94%0#N/A#N/A#N/ANo Change403-00_Active403-00_403-00_2.21808E+132.18034E+132.34455E+132.32703E+132.13711E+132.19559E+132.34576E+132.32089E+132.20241E+132.32954E+132.18373E+13
124.63924E+134.96095E+133.21714E+126.93%0#N/A#N/A#N/ANo Change108-00_Active108-00_108-00_3.22984E+133.25831E+133.73777E+133.61234E+133.51334E+133.41433E+133.50704E+133.4919E+133.51274E+133.65808E+133.40239E+13
135.51755E+136.82486E+166.81934E+16123593.60%131/07/202330/07/202301/08/20234.5412E+134.46555E+134.50338E+13Change206-00_Active206-00_206-00_4.84895E+134.55798E+134.74961E+134.2477E+134.3761E+134.64112E+134.67637E+134.1764E+134.65392E+136.82486E+164.44107E+13
145.25261E+137.21047E+167.20522E+16137174.12%107/07/202306/07/202308/07/20234.42827E+134.37339E+134.40083E+13Change219-00_Active219-00_219-00_2.13122E+132.08266E+132.08223E+137.21047E+161.92175E+131.77083E+131.92632E+131.85455E+132.03177E+131.92304E+131.78454E+13
153.58949E+137.2091E+167.20551E+16200738.91%114/08/202313/08/202315/08/20233.20029E+132.87905E+133.03967E+13Change215-00_Active215-00_215-00_2.57899E+133.1169E+133.01287E+132.98757E+132.74744E+137.2091E+163.03128E+132.79463E+133.08E+132.69527E+132.69774E+13
162.80592E+137.20753E+167.20473E+16256768.52%120/04/202319/04/202321/04/20231.99106E+131.68039E+131.83573E+13Change405-00_Active405-00_405-00_2.07905E+137.20753E+162.03198E+132.13614E+132.01161E+132.14677E+132.21228E+131.8983E+131.96145E+131.76097E+132.03697E+13
172.17752E+137.01804E+167.01587E+16322195.38%101/05/202330/04/202302/05/20231.87419E+132.95061E+141.56902E+14Change212-00_Active212-00_212-00_1.86716E+131.8463E+131.92229E+131.78519E+131.77784E+131.68654E+131.8098E+137.01804E+161.94947E+131.82121E+131.75575E+13
183.67045E+127.2061E+167.20573E+161963174.55%109/02/202308/02/202310/02/20233.4556E+121.76086E+122.60823E+12Change201-00_Active201-00_201-00_2.47656E+122.61643E+122.62939E+122.79215E+127.2061E+161.64502E+122.71797E+123.20158E+123.39275E+123.06009E+127.2061E+16
191.52361E+141.57775E+145.41368E+123.55%0#N/A#N/A#N/ANo Change343-00_Active343-00_343-00_1.01412E+149.98625E+131.05566E+141.12905E+141.19261E+141.02882E+141.15174E+141.10825E+141.05661E+141.33623E+141.04548E+14
201.12484E+141.20721E+148.23793E+127.32%0#N/A#N/A#N/ANo Change707-00_Active707-00_707-00_6.44394E+137.71739E+137.35691E+137.43816E+137.28574E+138.70437E+138.70779E+137.84663E+137.92791E+137.58194E+137.70722E+13
211.05509E+141.11848E+146.33914E+126.01%0#N/A#N/A#N/ANo Change428-00_Active428-00_428-00_6.35586E+138.2578E+137.46724E+137.89953E+137.56625E+137.44405E+137.86401E+137.49082E+137.5356E+137.37645E+137.1967E+13
221.27801E+141.30688E+142.88699E+122.26%0#N/A#N/A#N/ANo Change172-00_Active172-00_172-00_5.9024E+135.99894E+136.59582E+136.64529E+136.2487E+135.70194E+136.44993E+136.05956E+136.09441E+136.24502E+135.94318E+13
238.58339E+138.89753E+133.14144E+123.66%0#N/A#N/A#N/ANo Change209-00_Active209-00_209-00_7.70253E+137.19025E+137.29452E+136.79377E+136.63824E+136.74652E+137.06308E+136.12602E+136.68593E+135.99955E+136.75234E+13
248.34736E+138.4398E+139.24468E+111.11%0#N/A#N/A#N/ANo Change213-00_Active213-00_213-00_7.13665E+136.66799E+137.29732E+136.35129E+136.35211E+136.94525E+136.82313E+136.0591E+136.70254E+135.83124E+136.46105E+13
258.28309E+138.97382E+136.90728E+128.34%0#N/A#N/A#N/ANo Change206-00_Active206-00_206-00_7.18268E+136.84E+136.7977E+136.63546E+136.53581E+135.88576E+136.73027E+136.5402E+136.99695E+136.24803E+135.90705E+13
268.00764E+138.57892E+135.71275E+127.13%0#N/A#N/A#N/ANo Change296-00_Active296-00_296-00_6.75498E+136.28066E+136.62272E+136.07234E+136.47338E+136.28066E+136.59657E+136.08039E+136.53773E+136.01964E+136.33779E+13
27
28
Sheet1
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi vmjan02. "this takes 6 to 7 hrs" ... yuck!. It's snowing outside and it seems I have some time available. Can you post a sample wb? Dave
 
Upvote 0
@ NdNovicehlp
Have already posted the sample in my 1st post. in xl2bb, you can copy it, for working.

1698414258430.png
 
Upvote 0
Well isn't that handy. Is there actually an AC column? It copy/pasted but is not shown. Dave
yes data my vary this sampe data till AB, but columns may also go till XC as well, everday the colum and row data changes.

acutal data i have currently i am doing it is till KE and rows are 8000

so col and row will vary.
I hope i am clear now.
 
Upvote 0
The copy/paste thing doesn't want to work right? Anyways, if an "E" row = 1 then: if the B row value equals the same value as the N to last column row then: replace it with the K row value.
This seems like it should work. Please save a copy of your wb before testing. The code identifies the changed cells with red interior. Change the sheet name to suit. HTH. Dave
Code:
Sub test()
Dim LastCol As Integer, LastRow As Integer, Cnt As Integer, Cnt2 As Integer
Dim FindVal As Double, RepVal As Double, Rng As Range, r As Range
With Sheets("sheet1")
LastRow = .Range("E" & .Rows.Count).End(xlUp).Row
LastCol = .Cells(10, .Columns.Count).End(xlToLeft).Column
For Cnt = 9 To LastRow
If .Range("E" & Cnt) = 1 Then
For Cnt2 = Cnt To LastRow
    If .Range("E" & Cnt2) = 0 Then
    Cnt = Cnt2
    Exit For
    Else
    'it will find b13 from N13 to last non blank column and if found will replace it with K13.
    FindVal = .Range("B" & Cnt2)
    RepVal = .Range("K" & Cnt2)
    Set Rng = .Range(.Cells(Cnt2, "N"), .Cells(Cnt2, LastCol))
        For Each r In Rng
        If r.Value = FindVal Then
        r.Value = RepVal
        r.Interior.Color = vbRed
        End If
        Next r
    End If
Next Cnt2
End If '.Range("E" & Cnt) = 1
Next Cnt
End With
End Sub
 
Upvote 0
Solution
The copy/paste thing doesn't want to work right? Anyways, if an "E" row = 1 then: if the B row value equals the same value as the N to last column row then: replace it with the K row value.
This seems like it should work. Please save a copy of your wb before testing. The code identifies the changed cells with red interior. Change the sheet name to suit. HTH. Dave
Code:
Sub test()
Dim LastCol As Integer, LastRow As Integer, Cnt As Integer, Cnt2 As Integer
Dim FindVal As Double, RepVal As Double, Rng As Range, r As Range
With Sheets("sheet1")
LastRow = .Range("E" & .Rows.Count).End(xlUp).Row
LastCol = .Cells(10, .Columns.Count).End(xlToLeft).Column
For Cnt = 9 To LastRow
If .Range("E" & Cnt) = 1 Then
For Cnt2 = Cnt To LastRow
    If .Range("E" & Cnt2) = 0 Then
    Cnt = Cnt2
    Exit For
    Else
    'it will find b13 from N13 to last non blank column and if found will replace it with K13.
    FindVal = .Range("B" & Cnt2)
    RepVal = .Range("K" & Cnt2)
    Set Rng = .Range(.Cells(Cnt2, "N"), .Cells(Cnt2, LastCol))
        For Each r In Rng
        If r.Value = FindVal Then
        r.Value = RepVal
        r.Interior.Color = vbRed
        End If
        Next r
    End If
Next Cnt2
End If '.Range("E" & Cnt) = 1
Next Cnt
End With
End Sub

I have dug it

in Findval it is searching as 6.82.....+16 were as the actual value to search is 68248592160750700 and replace it wil 45033773320234.5

so its not replacing it, any way out

VBA Code:
 FindVal = .Range("B" & Cnt2)   '68248592160750700
 
Upvote 0
Not sure I understand. It's not replacing it with the correct value or it's replacing it but not with the extended value? Dave
 
Upvote 0
Not sure I understand. It's not replacing it with the correct value or it's replacing it but not with the extended value? Dave
no it is not replacing it,

I tried it wil

Dim FindVal As Double insted Dim FindVal As LongLong but no luck
 
Upvote 0
"no it is not deplacint it" .... I don't understand?

Is "B" the find value or replacement Value. Is "K" the find value or replacement value. Is the pic in #1 the before or after replacement? Dave
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,224
Members
452,620
Latest member
dsubash

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