Excel work sheets

harry234

New Member
Joined
Jun 7, 2024
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Not even sure I’m asking correctly

I have 2 sheets. 1 is called “Working”, whose data is collected from the folders menu. Using the “copy path” function and pasting the results to excel “working” sheet. (This is done because the file folder is continuously updated by files downloaded from the internet.)

Sheet 2 is an inventory of those files and has line item data associated with each line item.

What I would like to do is update the inventory sheet using the working sheet but keep all inventory data associated with respective line items.

Example: Inventory sheet

ItemSizeLocation 1
1​
100 RTV Silicone Industrial
2​
880 Crown Chassis Grease (Texas Refinery Corp)14,1oz TubeEL2


Example: Working sheet

1​
100 RTV Silicone Industrial
2​
880 Crown Chassis Grease
3​
Ace plumbers epoxy putty


If I download a file called, Say “123 Battery”, my working sheet will look like:

1​
100 RTV Silicone Industrial
123A Battery
2​
880 Crown Chassis Grease
3​
Ace plumbers epoxy putty
The objective would be to insert “123 Battery” in the alfa numerically correct line and keep relevant information attached to the line that was moved down. (Example Inventory Sheet below)

ItemSizeLocation 1
1​
100 RTV Silicone Industrial8oz canTool
2​
123 Battery
3​
880 Crown Chassis Grease (Texas Refinery Corp)14.1oz TubeEL2
4​
Ace plumbers epoxy putty20oz stickControl
 
Not tested. Please check all references and change where required.
It assumes that both sheets are in one workbook which also has the code in it.
VBA Code:
Sub Start_Somewhere()
Dim arrFiles, i As Long, j As Long
Dim wb1 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet
Dim sh1Arr, sh2Arr, misF
Set wb1 = ThisWorkbook
Set sh1 = wb1.Worksheets("Working")    '<----- Change as required
Set sh2 = wb1.Worksheets("Inventory")    '<----- Change as required
arrFiles = Application.GetOpenFilename("All Files (*.*), *.*", , , , True)    '<----- Choose as many files as needed.
With Sheets("Working")
    For i = LBound(arrFiles) To UBound(arrFiles)
        .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Value = Left(Dir(arrFiles(i)), InStrRev(Dir(arrFiles(i)), ".", -1, vbTextCompare) - 1)
    Next i
sh1Arr = sh1.Range("B4:B" & sh1.Cells(sh1.Rows.Count, 2).End(xlUp).Row).Value
sh2Arr = sh2.Range("B3:B" & sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Row).Value
    For j = LBound(sh1Arr) To UBound(sh1Arr)
        If IsError(Application.Match(sh1Arr(j, 1), sh2Arr, False)) Then misF = misF & sh1Arr(j, 1) & "|"
    Next j
misF = Split(misF, "|")
sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Offset(1).Resize(UBound(misF)).Value = Application.Transpose(misF)
    With sh2.Range("A2:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row).Resize(, sh2.Cells(2, sh2.Columns.Count).End(xlToLeft).Column)
        .Sort Key1:=.Cells(2, 2), Order1:=xlAscending, Header:=xlYes
    End With
    With sh2.Range("A3:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row)
        .Formula = "=ROW() - 2"
        .Value = .Value
    End With
End Sub
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Of course if you don't test there will be errors.
In this part, add the "End With" as shown here.
Row references etc. are based on the pictures in your first post.
Code:
With Sheets("Working")
    For i = LBound(arrFiles) To UBound(arrFiles)
        .Cells(.Rows.Count, 2).End(xlUp).Offset(1).Value = Left(Dir(arrFiles(i)), InStrRev(Dir(arrFiles(i)), ".", -1, vbTextCompare) - 1)
    Next i
End With    '<---- Add this
There are a couple mistakes in the following section so replace these 8 lines
Code:
sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Offset(1).Resize(UBound(misF)).Value = Application.Transpose(misF)
    With sh2.Range("A2:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row).Resize(, sh2.Cells(2, sh2.Columns.Count).End(xlToLeft).Column)
        .Sort Key1:=.Cells(2, 2), Order1:=xlAscending, Header:=xlYes
    End With
    With sh2.Range("A3:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row)
        .Formula = "=ROW() - 2"
        .Value = .Value
    End With
With
Code:
sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Offset(1).Resize(UBound(misF)).Value = Application.Transpose(misF)
    With sh2.Range("A2:A" & sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Row).Resize(, sh2.Cells(2, sh2.Columns.Count).End(xlToLeft).Column)
        .Sort Key1:=.Cells(3, 2), Order1:=xlAscending, Header:=xlYes
    End With
    With sh2.Range("A3:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row)
        .Formula = "=ROW() - 2"
        .Value = .Value
    End With
 
Upvote 0
More to Post #12.

In this line, change the 1 to a 2
Code:
With sh2.Range("A3:A" & sh2.Cells(sh2.Rows.Count, 1).End(xlUp).Row)    '<----- Change 1 to a 2
so it ends up to be
Code:
With sh2.Range("A3:A" & sh2.Cells(sh2.Rows.Count, 2).End(xlUp).Row)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,207
Members
452,618
Latest member
Tam84

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