Find and replace excel VBA trouble -


I currently have an Excel VBA project in which I created a button and change the basis Worksheet price Working on user input, where the user will provide a new hardware name, a quantity and the name of the sheet in which the new value should be updated. The name of the hardware is a unique value, so the quantity should be updated based on the hardware name.

The problem I am facing is that, when I try to update the values, the name of the hardware is getting well updated but where the quantity is only the quantity of that particular hardware name Not updating, but updating all the amounts that match the old volume as updating.

Here's how the code looks like.

  if Combo box 1 Value & lt; & Gt; VbNullString then sName = .ComboBox1.Text 'is the name of kickboxes if lane (.ldhw value) & gt; 0 and lane (.nwhw.value) & gt; = SOldText, replacement :: 0 then sOldText = .OldHW.Text 'OldHW and NewHW Name text box doing sNewText = .Cells.replace worksheet (SNAME) with .NewHW.Text = sNewText, lookAt: = xlWhole, _ SearchOrder: = xlByRows, Match CAS: = Wrong, Search Format: = Wrong, Change _ Change: If the wrong end with the end = if the lane (.ldqty.Value) & gt; 0 and lane (.Newqty.Value) & gt; 0 then qOldText = .Oldqty.Text qNewText = .Newqty.Text what worksheet (SNAME) .Cells.replace with: = qOldText, Replacement: = qNewText, lookAt: = xlWhole, _ SearchOrder: = xlByRows, MatchCase: = False, SearchFormat : = False, _ ReplaceFormat:. With end = false end if end if end with   

Please any input will be greatly appreciated ...

thanks

The problem here is that you are searching two different and independent / replacements. The result will be exactly the same as you describe, all the matching qOldText values ​​will be replaced.

The right approach when you sOldText search for cell finds it

  set oCell = Nothing Set a reference to oCell = return will have SName.UsedRange.Find: = sOldText, LookAt: = xlWhole, _SearchOrder: = xlByRows, MatchCase: = False, SearchFormat: = False   

then in sOldText cell and qOldText The position of the volume cell in cell relative to the chamber located in place should be dependent on sheet layout. For example, if the same line, use the following columns:

  If Osel is not Osel = sNewText oCell.Offset (0,1) = qNewText end if   

From your question it appears that qOldText has no use, unless I can not remember it.

Comments