VBA Compatibility Issues with Excel for Mac

babyjwhale

New Member
Joined
Nov 6, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I'm trying to set up a simple database with an input tab and a database tab. One of my primary users has a Mac and is experiencing errors when trying to run two of the macros. We are both O365 subscribers; I'm using Excel version 2411. For better or worse, I've used ChatGPT to create and troubleshoot these until they work great for me on Windows. Two issues:
1) a custom sub is not working. The input tab is basically a transposed table, as it's easier to input in a column rather than in a row, for this case. The Load Comps sub transposes into the database tab and Lease_Database table.
2) a JSON converter (downloaded from GitHub) is not working on Mac, though the code appears to work on Mac? I'm using the JSON Converter to geocode using Google API. JSON Converter: GitHub - VBA-tools/VBA-JSON: JSON conversion and parsing for VBA

For 1, here's the vba code. Anyone have any insight as to why it wouldn't work? If I recall from him telling me it didn't work, I think it was the ListObjects?
VBA Code:
Sub LeaseLoadComps()
    Dim dbWs As Worksheet
    Dim dbTable As ListObject
    Dim dbHeaders As Range
    Dim headerMap As Object
    Dim i As Long, j As Long
    Dim rowLabel As String
    Dim dbLastRow As Long
    Dim userName As String, creationDate As Date

    ' Set worksheet for Lease Database
    Set dbWs = ThisWorkbook.Sheets("Lease Database")

    ' Get the Lease_Database table dynamically
    On Error Resume Next
    Set dbTable = dbWs.ListObjects("Lease_Database")
    On Error GoTo 0
    If dbTable Is Nothing Then
        MsgBox "Error: Table 'Lease_Database' not found on Lease Database sheet.", vbExclamation
        Exit Sub
    End If

    ' Get the header range dynamically
    Set dbHeaders = dbTable.HeaderRowRange

    ' Ensure leaseInputRange is initialized
    If leaseInputRange Is Nothing Then
        Call LeaseInitializeInputRange
    End If

    ' Find the last row in the Lease_Database table
    dbLastRow = dbTable.ListRows.Count + dbHeaders.row + 1

    ' Create a dictionary to map Lease_Database headers to their respective columns
    Set headerMap = CreateObject("Scripting.Dictionary")
    For j = 1 To dbHeaders.Columns.Count
        headerMap(dbHeaders.Cells(1, j).value) = dbHeaders.Cells(1, j).Column
    Next j

    ' Fetch user details and timestamp
    userName = Environ("Username")
    creationDate = Date

    ' Loop through each column in Input (B to V)
    For j = 2 To leaseInputRange.Columns.Count
        If leaseInputRange.Cells(1, j).value <> "" Then ' Only process if column has data
            ' Write the data for the current column into a single row in Lease_Database
            For i = 1 To leaseInputRange.Rows.Count
                rowLabel = leaseInputRange.Cells(i, 1).value ' Row label from column B in leaseInputRange
                If headerMap.Exists(rowLabel) Then
                    dbWs.Cells(dbLastRow, headerMap(rowLabel)).value = leaseInputRange.Cells(i, j).value
                Else
                    Debug.Print "No match found for row label: " & rowLabel
                End If
            Next i

            ' Populate GlobalID, CreationDate, Creator
            dbWs.Cells(dbLastRow, headerMap("GlobalID")).value = CreateGlobalID()
            dbWs.Cells(dbLastRow, headerMap("CreationDate")).value = creationDate
            dbWs.Cells(dbLastRow, headerMap("Creator")).value = userName

            ' Move to the next row for the next column in Input
            dbLastRow = dbLastRow + 1
        End If
    Next j
End Sub

Happy to post more if needed. Let me know!
 

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.

Forum statistics

Threads
1,224,817
Messages
6,181,144
Members
453,021
Latest member
Justyna P

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