Results 1 to 10 of 10

Troubleshooting VBA Code Error and Clarifying Steps for Data Filtering and Formulas

Threaded View

  1. #1
    Forum Contributor
    Join Date
    09-02-2010
    Location
    singapore
    MS-Off Ver
    MS365
    Posts
    287

    Troubleshooting VBA Code Error and Clarifying Steps for Data Filtering and Formulas

    Dear Experts,

    I've been working with a VBA macro generated using ChatGPT that filters data based on specific criteria and retrieves additional information from an external workbook using INDEX and MATCH functions. However, I've encountered an error. I suspect the error are related to the functions.

    I hope someone here can assist me with troubleshooting this issue.

    I have attached a sample worksheet for your reference to facilitate understanding.

    Thank you in advance for your support!!!


    The steps required in the VBA are as follows:

    1. Filter Data: Show only the rows where:
    - Column AD is empty.
    - Column Z has "SMBC"

    2. Check for Data: Verify if any rows match the filter criteria. If no rows match, display a message stating that no data was found and stop the process. If there is a match, proceed to step 3.

    3. Formulas are applied to columns AD and AE to fetch data from this external workbook using INDEX and MATCH functions.
    Which is to retrieve data from columns K and M of an external workbook based on matches in column P.

    Path to an external workbook --> "R:\Shipping Group- SMBC INCOMING FUND REPORTS.xlsm".

    4. Clear Filter.

    5. Convert Formulas to Values: Convert the formulas in columns AD and AE into fixed values to prevent them from changing if the data in the external file changes.

    Sub SMBCFUNDS()
    '
    ' SMBC INCOMING FUNDS UPDATE - 25/6/24 version 1
    '
    
        Application.ScreenUpdating = False
        
        With ActiveSheet
            .AutoFilterMode = False
            .Rows("4:4").AutoFilter
            
            With .Range("$A$5:$BG$" & .Cells(.Rows.COUNT, 1).End(xlUp).Row)
                .AutoFilter Field:=30, Criteria1:="="
                .AutoFilter Field:=26, Criteria1:="SMBC"
            End With
    
            On Error Resume Next
            Dim visibleRows As Long
            visibleRows = .Range("$A$5:$A$" & .Cells(.Rows.COUNT, 1).End(xlUp).Row).SpecialCells(xlCellTypeVisible).COUNT
            On Error GoTo 0
            
            If visibleRows <= 1 Then
                .ShowAllData
                MsgBox "No rows found matching the criteria. Process stopped."
                Application.ScreenUpdating = True
                Exit Sub
            End If
    
            Dim wbPath As String
            wbPath = "R:\Shipping Group\- SMBC INCOMING FUND REPORTS.xlsm"
            
            Dim lastRow As Long
            lastRow = .Cells(.Rows.COUNT, 1).End(xlUp).Row
            
            With .Range("AD5:AE" & lastRow).SpecialCells(xlCellTypeVisible)
                .FormulaR1C1 = "=IFERROR(INDEX('" & wbPath & "'!$K:$K, MATCH(RC[-22],'" & wbPath & "'!$P:$P, 0)), """")"
                .Offset(, 1).FormulaR1C1 = "=IFERROR(INDEX('" & wbPath & "'!$M:$M, MATCH(RC[-23],'" & wbPath & "'!$P:$P, 0)), """")"
            End With
            
            Application.Calculation = xlCalculationManual
            
            .Range("AD5:AE" & lastRow).Value = .Range("AD5:AE" & lastRow).Value
    
        End With
    
        Application.Calculation = xlCalculationAutomatic
        Application.ScreenUpdating = True
    
        MsgBox "Payment Updated!"
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Code Troubleshooting
    By Keegan1116 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 05-17-2024, 08:18 AM
  2. Floor Plan Macro - Need help troubleshooting 'Run time error 9' error message
    By liddy in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2021, 03:23 AM
  3. [SOLVED] Troubleshooting syntax error
    By Mr_Phil in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2021, 11:08 PM
  4. [SOLVED] Combine formulas in two steps
    By lamlam28 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-03-2019, 05:33 AM
  5. Replies: 2
    Last Post: 07-25-2018, 04:27 PM
  6. Autofilter vba not actually filtering - manual steps needed to filter- help
    By joshnathan in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-05-2014, 01:36 PM
  7. troubleshooting formulas
    By freshfruit in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-24-2014, 08:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1