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 7616581
In Process

The Archive Base Latest Questions

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

The ideal solution for this would be in VBA and not a formula because

  • 0

The ideal solution for this would be in VBA and not a formula because I need the first sheet to reset itself each time thus a formula would get overwritten.

I have two sheets:

Sheet1 (Subtract Inventory)

Item#   Sold
1022    23
1024    56
1025    52

Sheet2 (Count)

Item#   Count
1020    1027
1021    99
1022    76
1023    128
1024    57
1025    1023
1026    987

What I would like to do is have VBA code that will update Sheet2 by subtracting the “Sold” on Sheet1 from the “Count” on Sheet2. The result would look something like this:

Sheet2 (Count)

Item#   Count
1020    1027
1021    99
1022    53
1023    128
1024    1
1025    971
1026    987

I have been able to figure out several codes but I can never get them to fit. And Sheet1 will have users paste info from a website so it will have to base the search on the Item number and not column A.

I think the best thing to do is a restart to make sure that I am not messing up by starting off in the wrong direction. Does anyone have any idea where to begin?

  • 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-31T02:55:29+00:00Added an answer on May 31, 2026 at 2:55 am

    Another way using Vlookup

    Hope this is what you are trying?

    TRIED AND TESTED

    Option Explicit
    
    Sub Sample()
        Dim ws1 As Worksheet, ws2 As Worksheet
        Dim ws1LastRow As Long, ws2LastRow As Long, i As Long
        Dim SearchRange As Range
    
        Set ws1 = Sheets("Sheet1")
        ws1LastRow = ws1.Range("A" & ws1.Rows.Count).End(xlUp).Row
    
        Set SearchRange = ws1.Range("A1:B" & ws1LastRow)
    
        Set ws2 = Sheets("Sheet2")
    
        With ws2
            ws2LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    
            For i = 2 To ws2LastRow
                On Error Resume Next
                If Not IsError(Application.WorksheetFunction.VLookup(.Range("A" & i).Value, SearchRange, 2, False)) Then
                    .Range("B" & i).Value = .Range("B" & i).Value - _
                    Application.WorksheetFunction.VLookup(.Range("A" & i).Value, SearchRange, 2, False)
                End If
                On Error GoTo 0
            Next i
        End With
    
        '~~> Clear Sheet1 for next input
        ws1.Cells.ClearContents
    
        '~~> Clean Up
        Set SearchRange = Nothing
        Set ws1 = Nothing
        Set ws2 = Nothing
    End Sub
    

    SNAPSHOT

    enter image description here

    FOLLOWUP

    The cleaning that you are doing at the moment is not correct. If I manually do the cleaning the sheet should look like this?

    enter image description here

    Also if you notice that then numbers are stored as text or have blank spaces. Vlookup will fail in these scenarios.

    enter image description here

    In such a case, I recommend the following

    1) You need to have a macro in places which cleans your data more effectively for input

    2) Either you move the “SKU” before the “QTY” and then use Vlookup OR use an alternate method.

    3) If you are interested in an alternate method then see (Section 4) in this link

    http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/

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

Sidebar

Related Questions

This should be an ideal case of not re-inventing the wheel, but so far
First, I know about this: How would you organize a Subversion repository for in
First I remove control visibility by doing this: For Each ctl In Me.MySubform.Controls ctl.Visible
First of all, I know this is a bad solution and I shouldn't be
Here is my ideal solution: a free tool that reads a .csporj or .sln
What is the ideal code to logging ratio? I'm not used to writing logs
In my ideal world, what I'm looking for would exist as something along the
I have a question on a solution I think is secure, but would like
I would appreciate some help before spending any more time on trial and error.
I have a multi-project solution being stored in TFS. Each project has separate Debug/Release

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.