WTHamIdoing
New Member
- Joined
- Aug 5, 2023
- Messages
- 10
- Office Version
- 365
- Platform
- Windows
I have a workbook that has a custom function in it. A custom function was the only way to make xcel give back the data needed. I want to use the workbook as a template to merge date from our CRM into. Unfortuntately FormStack (The app that does the merge from our CRM to Excel) does not support macro enabled workbooks. Anyone have an idea how I can make the resulting spreadsheet (*.xlsx) still utilize the function?
Below is the bulk of the function. THere are two other small pieces but I dont think they matter to my question.
Function CustomSummary(init_tab As String, end_tab As String, keyword As String, columnToSearch As String, columnToReturn As String) As Variant
Dim ws As Worksheet
Dim startFound As Boolean
Dim endFound As Boolean
Dim sumResult As Double
sumResult = 0
startFound = False
endFound = False
Dim initTabExists As Boolean
Dim endTabExists As Boolean
initTabExists = False
endTabExists = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name = init_tab Then
initTabExists = True
startFound = True
If endFound Then
CustomSummary = "End tab '" & end_tab & "' found before Init tab '" & init_tab & "'."
Exit Function
End If
End If
If startFound And ws.Name <> init_tab And ws.Name <> end_tab Then
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, columnToSearch).End(xlUp).Row
Dim rng As Range
Set rng = ws.Range(columnToSearch & "1:" & columnToSearch & lastRow)
Dim cell As Range
Dim buffer_val As Variant
For Each cell In rng
If cell.Value = keyword Then
Set buffer_val = ws.Range(columnToReturn & cell.Row)
If IsNumeric(buffer_val) Then
sumResult = sumResult + buffer_val.Value
End If
End If
Next cell
End If
If ws.Name = end_tab Then
endTabExists = True
endFound = True
If Not startFound Then
CustomSummary = "Init tab '" & init_tab & "' not found."
Exit Function
End If
Exit For
End If
Next ws
If Not initTabExists Then
CustomSummary = "Init tab '" & init_tab & "' not found."
Exit Function
End If
If Not endTabExists Then
CustomSummary = "End tab '" & end_tab & "' not found."
Exit Function
End If
CustomSummary = sumResult
End Function
Below is the bulk of the function. THere are two other small pieces but I dont think they matter to my question.
Function CustomSummary(init_tab As String, end_tab As String, keyword As String, columnToSearch As String, columnToReturn As String) As Variant
Dim ws As Worksheet
Dim startFound As Boolean
Dim endFound As Boolean
Dim sumResult As Double
sumResult = 0
startFound = False
endFound = False
Dim initTabExists As Boolean
Dim endTabExists As Boolean
initTabExists = False
endTabExists = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name = init_tab Then
initTabExists = True
startFound = True
If endFound Then
CustomSummary = "End tab '" & end_tab & "' found before Init tab '" & init_tab & "'."
Exit Function
End If
End If
If startFound And ws.Name <> init_tab And ws.Name <> end_tab Then
Dim lastRow As Long
lastRow = ws.Cells(ws.Rows.Count, columnToSearch).End(xlUp).Row
Dim rng As Range
Set rng = ws.Range(columnToSearch & "1:" & columnToSearch & lastRow)
Dim cell As Range
Dim buffer_val As Variant
For Each cell In rng
If cell.Value = keyword Then
Set buffer_val = ws.Range(columnToReturn & cell.Row)
If IsNumeric(buffer_val) Then
sumResult = sumResult + buffer_val.Value
End If
End If
Next cell
End If
If ws.Name = end_tab Then
endTabExists = True
endFound = True
If Not startFound Then
CustomSummary = "Init tab '" & init_tab & "' not found."
Exit Function
End If
Exit For
End If
Next ws
If Not initTabExists Then
CustomSummary = "Init tab '" & init_tab & "' not found."
Exit Function
End If
If Not endTabExists Then
CustomSummary = "End tab '" & end_tab & "' not found."
Exit Function
End If
CustomSummary = sumResult
End Function