I have to add a new function for inventory tracking but the code i came up with only works with some codes not all

svis89

Board Regular
Joined
Oct 19, 2021
Messages
67
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
    If Range("B2") = "" Then
Exit Sub
End If
  
    mycol = Sheets("Count sheet").Rows(1).Find("Defect", , xlValues, , xlByColumns, xlPrevious).Column
    Set CngB = Columns(mycol)
        
    RngB = Sheets("Inventory management").Range("B2").Value


    For Each cell In Sheets("Count sheet").Range("A2:A8000")
        If cell.Value = RngB Then Sheets("Count sheet").Cells(cell.Row, mycol).Offset(, 2) = Sheets("Inventory management").Range("E2")
    Next
    
    Sheets("Count sheet").Columns(mycol + 2).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    
    Range("A2:F2").Select
    Selection.Copy
    Sheets("Added to inv").Select
    Range("A5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Rows("4:4").Select
    Application.CutCopyMode = False
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
    Range("A5").Select
    Sheets("Inventory management").Range("E2").ClearContents
    Sheets("Inventory management").Range("B2").ClearContents
    
End Sub
 
i want to enter the data on the inventory management screen hit the correct button for add remove or scrap have it do that on the count sheet and also copy the data to another so i can see what was changed when
it is not copying the data to the inv changes sheet for these two formula's It worked fine on the added to inventory formula but on these two it will not
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
i want to enter the data on the inventory management screen hit the correct button for add remove or scrap have it do that on the count sheet and also copy the data to another so i can see what was changed when
it is not copying the data to the inv changes sheet for these two formula's It worked fine on the added to inventory formula but on these two it will not
OK, I think we are slowly, but surely making progress. I still want some concrete examples though, so I can test it out on my side.

Walk me through an actual example when it is working the way you like.
1. What exactly are you entering in which cell?
2. Which VBA code are you triggering?
3. What happens on the other sheets (what cells are updated with what values)?

Then, walk me through an actual example where it is NOT working, providing the same three bits of information.
 
Upvote 0
OK, I think we are slowly, but surely making progress. I still want some concrete examples though, so I can test it out on my side.

Walk me through an actual example when it is working the way you like.
1. What exactly are you entering in which cell?
2. Which VBA code are you triggering?
3. What happens on the other sheets (what cells are updated with what values)?

Then, walk me through an actual example where it is NOT working, providing the same three bits of information.
Inventory management i enter a item number in B2 C2-E2 i put the amount added removed or scrapped only in category is picked then i add the initials of who is responsible for the change.
Depending on if i added removed or scrapped i hit the appropriate button Bought i got working on my own Sold and Defect are not working correctly.
What happens next is the data goes to the count sheets and adds subtracts or scraps for the appropriate item number They all are working correctly this far.
Then they are supposed to copy what i entered in the inventory managment screen to the inv changes screen on line 5 then insert a row making it line 6 so line 5 is open for the next time it is not doing anything on the inv changes screen
 
Upvote 0
I solved my problem i created this using record function and then made my changes to it over time. one of my changes was changing the name of the sheet which i did not do in the code
 
Upvote 0
Solution
Glad you figured it out. I was just about to ask you if you were able to share your workbook, as I still didn't have quite have all the details I needed.

Note in situations like this, I often like to step into my code, and go through one line at a time using the F8 key.
If you have two monitors, you can have your code on one, and your workbook on the other (or you can split the screen), and you can watch exactly what is happening as you step through the code.
Many times it becomes very evident what the problem is when you see it, especially when you see which sections of code it skips over, and when you see what is happening to each sheet.
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,423
Members
448,961
Latest member
nzskater

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