Simple UDF not providing the expected answer

OaklandJim

Well-known Member
Joined
Nov 29, 2018
Messages
849
Office Version
  1. 365
Platform
  1. Windows
This seems so basic but I have not done programming for a while so I need a second set of eyes. In investment portfolio spreadsheet I am trying to add up cash held (money market funds). I loop through holdings' names looking for the word MONEY (all caps). The function seems to find the occurrences as expected. But I cannot get/sum the VALUE for each one entry found. The value is offset by five columns from the holding names column. What super basic concept am I screwing up?

VBA Code:
Option Explicit

' ----------------------------------------------------------------
' Procedure Name: AmountCash
' Purpose: Sum cash holdings. Based on name of holding containing "MONEY"
' Procedure Kind: Function
' Procedure Access: Public
' Parameter prHoldingNames (Range):
' Return Type: Double
' Author: Jim
' Date: 7/20/2024
' ----------------------------------------------------------------
Function AmountCash(prHoldingNames As Range) As Double

    Dim rCell As Range
    
    Dim iAmountValueColOffset As Long
    
    iAmountValueColOffset = 5
    
    For Each rCell In prHoldingNames
    
        If UCase(rCell.Value) Like "*MONEY*" _
         Then

Debug.Print rCell.Offset(0, iAmountValueColOffset).Value
'Debug.Print rCell.Cells(1, 6).Value
            AmountCash = AmountCash + rCell.Offset(0, iAmountValueColOffset).Value
        End If
    
    Next rCell

End Function

Immediate window result
True
True
True
True
True
True

Portfolio_ver1a.xlsm
ABCDEFH
5NameSymbolAccount NameAccount #Portion BondsValue
61.HELD IN MONEY MARKETFDRXX683.81
72.VANGUARD HIGH YIELD CORP INVESTOR CLVWEHX18,894.36
83.NNN REIT INC COMNNN3,541.25
94.ISHARES TR US HOME CONS ETFITB10,459.82
105.ALEXANDRIA REAL ESTATE EQUITIES COM USD0.01ARE3,205.38
116.MID-AMER APT CMNTYS INC COMMAA4,506.43
127.FIDELITY FLOATING RATE HIGH INCOMEFFRHX2,459.19
138.VICI PPTYS INC COMVICI10,349.05
149.REXFORD INDUSTRIAL REALTY INREXR3,205.90
1510.HELD IN MONEY MARKETSPAXX14,218.89
1611.VANGUARD PRIMECAP FUND INVESTOR CLASSVPMCX53,621.92
1712.INVESCO QQQ TR UNIT SER 1QQQ9,884.99
1813.HELD IN MONEY MARKETFDRXX2,255.04
1914.HELD IN MONEY MARKETFDRXX5,305.79
2015.FEDERAL RLTY INVT TR NEW SH BEN INT NEWFRT12,474.24
2116.FIDELITY STRATEGIC INCOME FUNDFADMX4,902.66
2217.INVESCO EXCH TRD SLF IDX FD TR BULSHS 2025 CBBSCP115,654.69
2318.VANGUARD DIVIDEND GROWTH INVESTOR CLVDIGX30,363.87
2419.INVESCO EXCH TRD SLF IDX FD TR BULSHS 2026 CBBSCQ115,760.91
2520.FIDELITY SELECT BIOTECHNOLOGYFBIOX13,759.23
2621.DODGE & COX INCOME CL IDODIX111,231.41
2722.VANGUARD SCOTTSDALE FUNDS VANGUARD INTER-TERM CORP BD ETFVCIT125,323.20
2823.FIRST TR EXCHANGE TRADED FD VI NASDAQ TECH DIVID INDEX FDTDIV23,539.49
2924.INVESCO EXCH TRD SLF IDX FD TR BULSHS 2027 CBBSCR115,892.48
3025.VANGUARD INTERNATL VALUE PORT INV CLVTRIX25,280.03
3126.INVESCO EXCH TRD SLF IDX FD TR BULETSHS 2029BSCT116,077.42
3227.INVESCO EXCH TRD SLF IDX FD TR INVSCO BLSH 28BSCS115,988.56
3328.SELECT SECTOR SPDR TRUST TECHNOLOGY SELECT SECTOR USD DISXLK7,564.99
3429.ISHARES TR ISHARES SEMICDTRSOXX27,691.85
3530.VANECK ETF TRUST VANECK VIETNAMVNM3,856.00
3631.GOVT NATL MTG ASSN POOL #551769 6.00000% 04/15/203236213D6E3121.82
3732.HELD IN MONEY MARKETSPAXX22,630.67
3833.VANGUARD SPECIALIZED FUNDS DIV APP ETFVIG83,922.25
3934.VANGUARD MEGA CAP VALUE INDEX FUNDMGV13,187.52
4035.VANGUARD WHITEHALL FDS HIGH DIV YLDVYM6,088.20
4136.VANGUARD INDEX FDS VANGUARD TOTAL STK MKT ETFVTI5,985.00
4237.FIDELITY EXTENDED MARKET INDEX FUNDFSMAX2,642.87
4338.VANGUARD SCOTTSDALE FUNDS VANGUARD INTER-TERM CORP BD ETFVCIT1127,003.60
4439.VANGUARD SMALL CAP VALUE ETFVBR52,553.90
4540.INVESCO EXCHANGE TRADED FD TR S&P 500 TOP 50XLG20,171.06
4641.VANGUARD PRIMECAP CORE FD INVESTOR CLVPCCX22,568.79
4742.HELD IN MONEY MARKETFDRXX1,549.57
4843.VANGUARD/WELLESLEY INCOME INVESTORVWINX0.67,214.80
4944.DODGE & COX STOCK CL IDODGX3,955.21
5045.INVESCO EXCH TRD SLF IDX FD TR BULSHS 2025 HYBSJP15,165.44
5146.SIMON PROPERTY GROUP INCSPG16,204.32
5247.VANGUARD WELLINGTON INVESTORVWELX0.427,340.84
5348.FIDELITY INTERNATL INDEX FUNDFSPSX17,516.58
5449.INVESCO EXCHANGE TRADED SELF IDX FT INVESCO BULLETSHS 2028 HGH YIELD CORBSJS5,205.60
5550.DODGE & COX INTERNATL STOCK CL IDODFX29,892.15
5651.INVESCO EXCH TRD SLF IDX FD TR BULETSHS 2027BSJR15,151.74
5752.INVESCO EXCH TRD SLF IDX FD TR INVSCO BLSH 26BSJQ15,214.72
5853.REALTY INCOME CORP COMO14,556.22
5954.FIDELITY SELECT MED TECHNOLOGY & DEVICESFSMEX12,407.52
6055.CROWN CASTLE INC COMCCI3,698.82
Portfolio
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Looks like the offset should be 6 & not 5.
 
Upvote 0
Solution
Oy. You noticed the hidden column that I missed. Your solution works as expected. Thank you so much for the assist!
 
Upvote 0
Glad we could help & thanks for the feedback.
 
Upvote 0
Oy. You noticed the hidden column that I missed. Your solution works as expected. Thank you so much for the assist!
The marked solution has been changed accordingly. In your future questions, please mark the post as the solution that actually answered your question, instead of your feedback message as it will help future readers. No further action is required for this thread.
 
Upvote 0

Forum statistics

Threads
1,221,653
Messages
6,161,067
Members
451,684
Latest member
smllchng5

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