Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4235264
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:28:27+00:00 2026-05-21T02:28:27+00:00

I am currently working on a Excel VBA project in which I have created

  • 0

I am currently working on a Excel VBA project in which I have created a button to find and replace the value in the worksheet depending on the user input, where user will provide a new hardware name, a quantity and the sheet name in which the new value needs to be updated. The hardware name is a unique value, so the update of the quantity should happen depending on the hardware name.

The problem I am facing is that, when I try to update the values, the hardware name is getting updated properly but where as while updating the quantity it is not only updating the quantity of that particular hardware name but is updating all the quantity that matches the old quantity.

Here is how the code looks like:

If .ComboBox1.Value <> vbNullString Then
         sName = .ComboBox1.Text 'is combobox name

         If Len(.OldHW.Value) > 0 And Len(.NewHW.Value) > 0 Then
             sOldText = .OldHW.Text 'OldHW and NewHW are textbox names
             sNewText = .NewHW.Text         

             With Worksheets(sName)
                 .Cells.replace what:=sOldText, Replacement:=sNewText, LookAt:=xlWhole, _
                     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                     ReplaceFormat:=False                         

             End With
         End If


        If Len(.Oldqty.Value) > 0 And Len(.Newqty.Value) > 0 Then
            qOldText = .Oldqty.Text
           qNewText = .Newqty.Text

             With Worksheets(sName)
                 .Cells.replace what:=qOldText, Replacement:=qNewText, LookAt:=xlWhole, _
                     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
                     ReplaceFormat:=False

             End With
         End If    
     End If
 End With

Please any input will be greatly appreciated…

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T02:28:27+00:00Added an answer on May 21, 2026 at 2:28 am

    The problem here is that you are doing two seperate and independant search/replace operations. The result will be exactly what you describe, all matching qOldText values will be replaced.

    The correct approach would be when you search for the sOldText return a reference to the cell it finds

    Set oCell = Nothing
    Set oCell = sName.UsedRange.Find what:=sOldText, LookAt:=xlWhole, _
                     SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
    

    Then replace sOldText in the located cell and qOldText in a cell relative to the located cell. The position of the Qty cell must depend on the sheet layout. For example if its in the same row, next column use:

    If Not oCell is Nothing then
        oCell =  sNewText 
        oCell.Offset(0,1) = qNewText
    End If
    

    From your question it would seem qOldText has no use, unless there is somthing I’ve missed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a project to convert a number of Excel VBA
I'm currently working on a project in which i need to read some (Latitude,
I am currently working on a project and my goal is to locate text
I'm currently working on creating a new C# project that needs to interact with
I am currently working on a project with specific requirements. A brief overview of
The system I am currently working on requires some role-based security, which is well
The company I'm currently working for is using Selenium for Uniting-Testing our User Interface.
Currently working on something which uses ajax for some pagination. What I'm looking to
I'm currently working on a Win32 program which requires a main window containing many
I am currently working on a Java EJB project being deployed to Weblogic 10.3.3.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.