Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Formula/Macro | Lookup a List of CSVs, Return Two Lists of CSVs

0

Hello,

I'm looking for some automation for a workflow (see attached workbook for details) that goes a bit like this:

Workflow A:

  1. Lookup the price of the first comma-separated value in H*
  2. Multiply it by the first comma-separated value in I*
  3. Repeat for all values in H*
  4. Summarize
  5. Multiply the sum by (1-(the discount percentage in J*))
  6. Display the final discounted sum in K*.

Workflow B:

  1. Lookup the category of the first comma-separated value in H*
  2. List the category in M*
  3. Repeat for all values in H*
  4. Remove duplicates

Notes:

  • As I mentioned in my lead, I'm looking for these workflows to be automated. So, I'm hoping to use a formula rather than a macro (unless a macro can be automated to run in a similar fashion as a formula).
  • I have two tables for looking up prices and categories in the sheet labeled 'VLOOKUP Tables'
  • I have a list of discounts that are used for data validation in column J. Find this list in the sheet labeled 'Data Validation Table.' J is allowed to blank, and this should be used to represent a discount of 0%.

The thing that is giving me the most trouble is that I'm working with comma-separated values (CSVs). I've more or less mastered VLOOKUPs on cells with individual values, but the CSVs are killing me. Any insight into how best to typically handle these would also be greatly appreciated.

Please let me know if any additional clarification is required. Thank you in advance for your time and consideration!

Answer
Discuss

Answers

0
Selected Answer

I think you  may not have found quite the right approach yet. Therefore I suggest another. The code below will split the data in your Returns sheet into separate rows for each SKU.

Sub SplitReturnData()
    ' Variatus @TeachExcel 25 Feb 2020

    Dim SpSKU() As String, SpQty() As String
    Dim Arr As Variant
    Dim R As Long
    Dim i As Integer

    Application.ScreenUpdating = False
    ' change the tab's name as appropriate
    ' replace Table index with table name if there are more tables on the sheet
    With Worksheets("Returns Tracking (2)").ListObjects(1)
        For R = .ListRows.Count To 1 Step -1
            If WorksheetFunction.CountA(.ListRows(R).Range) Then
                Arr = .ListRows(R).Range.Value
                SpSKU = Split(Arr(1, NrtSKU), ",")
                SpQty = Split(Arr(1, NrtQty), ",")
                If UBound(SpSKU) Then
                    For i = UBound(SpSKU) To 1 Step -1
                        With .ListRows.Add(R + 1).Range
                            .Value = Arr
                            .Cells(NrtSKU).Value = Trim(SpSKU(i))
                            On Error Resume Next                ' in case quantity is missing
                            .Cells(NrtQty).Value = CInt(SpQty(i))
                        End With
                        With .ListRows(R).Range
                            .Cells(NrtSKU).Value = Trim(SpSKU(0))
                            .Cells(NrtQty).Value = CInt(SpQty(0))
                            On Error GoTo 0
                        End With
                    Next i
                End If
            End If
        Next R
    End With
    Application.ScreenUpdating = True
End Sub

Replace the formula for the total in column B with this array formula (confirm with Ctl+Shift+Enter).

=SUM(IF([SO'#]<>"",1/COUNTIF([SO'#],[SO'#])))

With this setup all the Vlookups become easy, easier still if you combine the two tables you now have into one and return either the first or second column with your formula, the lookup value being the same for both.

This setup would greatly increase the flexibility of your data. For example, you would be able to scrap individual items instead of having to scrap them by batch. But it would deprive you of the overview your current setup affords. This, however, is standard reporting. One just takes the available data and compresses them into whatever shape is desirable. In this case that would mean code doing the precise opposite of what the above procedure does except that, by the time you get done with the idea, the reversal probably won't be so precise. Having the freedom to design the report the way you want you would probably avail yourself of that opportunity to make some amendments.

Please take a look if this suggestion could work for you.

Discuss

Discussion

Thanks for the help Variatus.

We switched up our approach to this report. So, unfortunately, we won't be using the code provided. I can say that it works as intended.
ConnorL (rep: 4) Mar 2, '20 at 8:04 am
Connor, thanks for the feedback.
Variatus (rep: 4889) Mar 2, '20 at 7:48 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login