OaklandJim
Well-known Member
- Joined
- Nov 29, 2018
- Messages
- 855
- Office Version
- 365
- Platform
- 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?
Immediate window result
True
True
True
True
True
True
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 | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | H | ||||
5 | Name | Symbol | Account Name | Account # | Portion Bonds | Value | ||||
6 | 1. | HELD IN MONEY MARKET | FDRXX | 683.81 | ||||||
7 | 2. | VANGUARD HIGH YIELD CORP INVESTOR CL | VWEHX | 1 | 8,894.36 | |||||
8 | 3. | NNN REIT INC COM | NNN | 3,541.25 | ||||||
9 | 4. | ISHARES TR US HOME CONS ETF | ITB | 10,459.82 | ||||||
10 | 5. | ALEXANDRIA REAL ESTATE EQUITIES COM USD0.01 | ARE | 3,205.38 | ||||||
11 | 6. | MID-AMER APT CMNTYS INC COM | MAA | 4,506.43 | ||||||
12 | 7. | FIDELITY FLOATING RATE HIGH INCOME | FFRHX | 2,459.19 | ||||||
13 | 8. | VICI PPTYS INC COM | VICI | 10,349.05 | ||||||
14 | 9. | REXFORD INDUSTRIAL REALTY IN | REXR | 3,205.90 | ||||||
15 | 10. | HELD IN MONEY MARKET | SPAXX | 14,218.89 | ||||||
16 | 11. | VANGUARD PRIMECAP FUND INVESTOR CLASS | VPMCX | 53,621.92 | ||||||
17 | 12. | INVESCO QQQ TR UNIT SER 1 | QQQ | 9,884.99 | ||||||
18 | 13. | HELD IN MONEY MARKET | FDRXX | 2,255.04 | ||||||
19 | 14. | HELD IN MONEY MARKET | FDRXX | 5,305.79 | ||||||
20 | 15. | FEDERAL RLTY INVT TR NEW SH BEN INT NEW | FRT | 12,474.24 | ||||||
21 | 16. | FIDELITY STRATEGIC INCOME FUND | FADMX | 4,902.66 | ||||||
22 | 17. | INVESCO EXCH TRD SLF IDX FD TR BULSHS 2025 CB | BSCP | 1 | 15,654.69 | |||||
23 | 18. | VANGUARD DIVIDEND GROWTH INVESTOR CL | VDIGX | 30,363.87 | ||||||
24 | 19. | INVESCO EXCH TRD SLF IDX FD TR BULSHS 2026 CB | BSCQ | 1 | 15,760.91 | |||||
25 | 20. | FIDELITY SELECT BIOTECHNOLOGY | FBIOX | 13,759.23 | ||||||
26 | 21. | DODGE & COX INCOME CL I | DODIX | 1 | 11,231.41 | |||||
27 | 22. | VANGUARD SCOTTSDALE FUNDS VANGUARD INTER-TERM CORP BD ETF | VCIT | 1 | 25,323.20 | |||||
28 | 23. | FIRST TR EXCHANGE TRADED FD VI NASDAQ TECH DIVID INDEX FD | TDIV | 23,539.49 | ||||||
29 | 24. | INVESCO EXCH TRD SLF IDX FD TR BULSHS 2027 CB | BSCR | 1 | 15,892.48 | |||||
30 | 25. | VANGUARD INTERNATL VALUE PORT INV CL | VTRIX | 25,280.03 | ||||||
31 | 26. | INVESCO EXCH TRD SLF IDX FD TR BULETSHS 2029 | BSCT | 1 | 16,077.42 | |||||
32 | 27. | INVESCO EXCH TRD SLF IDX FD TR INVSCO BLSH 28 | BSCS | 1 | 15,988.56 | |||||
33 | 28. | SELECT SECTOR SPDR TRUST TECHNOLOGY SELECT SECTOR USD DIS | XLK | 7,564.99 | ||||||
34 | 29. | ISHARES TR ISHARES SEMICDTR | SOXX | 27,691.85 | ||||||
35 | 30. | VANECK ETF TRUST VANECK VIETNAM | VNM | 3,856.00 | ||||||
36 | 31. | GOVT NATL MTG ASSN POOL #551769 6.00000% 04/15/2032 | 36213D6E3 | 1 | 21.82 | |||||
37 | 32. | HELD IN MONEY MARKET | SPAXX | 22,630.67 | ||||||
38 | 33. | VANGUARD SPECIALIZED FUNDS DIV APP ETF | VIG | 83,922.25 | ||||||
39 | 34. | VANGUARD MEGA CAP VALUE INDEX FUND | MGV | 13,187.52 | ||||||
40 | 35. | VANGUARD WHITEHALL FDS HIGH DIV YLD | VYM | 6,088.20 | ||||||
41 | 36. | VANGUARD INDEX FDS VANGUARD TOTAL STK MKT ETF | VTI | 5,985.00 | ||||||
42 | 37. | FIDELITY EXTENDED MARKET INDEX FUND | FSMAX | 2,642.87 | ||||||
43 | 38. | VANGUARD SCOTTSDALE FUNDS VANGUARD INTER-TERM CORP BD ETF | VCIT | 1 | 127,003.60 | |||||
44 | 39. | VANGUARD SMALL CAP VALUE ETF | VBR | 52,553.90 | ||||||
45 | 40. | INVESCO EXCHANGE TRADED FD TR S&P 500 TOP 50 | XLG | 20,171.06 | ||||||
46 | 41. | VANGUARD PRIMECAP CORE FD INVESTOR CL | VPCCX | 22,568.79 | ||||||
47 | 42. | HELD IN MONEY MARKET | FDRXX | 1,549.57 | ||||||
48 | 43. | VANGUARD/WELLESLEY INCOME INVESTOR | VWINX | 0.6 | 7,214.80 | |||||
49 | 44. | DODGE & COX STOCK CL I | DODGX | 3,955.21 | ||||||
50 | 45. | INVESCO EXCH TRD SLF IDX FD TR BULSHS 2025 HY | BSJP | 1 | 5,165.44 | |||||
51 | 46. | SIMON PROPERTY GROUP INC | SPG | 16,204.32 | ||||||
52 | 47. | VANGUARD WELLINGTON INVESTOR | VWELX | 0.4 | 27,340.84 | |||||
53 | 48. | FIDELITY INTERNATL INDEX FUND | FSPSX | 17,516.58 | ||||||
54 | 49. | INVESCO EXCHANGE TRADED SELF IDX FT INVESCO BULLETSHS 2028 HGH YIELD COR | BSJS | 5,205.60 | ||||||
55 | 50. | DODGE & COX INTERNATL STOCK CL I | DODFX | 29,892.15 | ||||||
56 | 51. | INVESCO EXCH TRD SLF IDX FD TR BULETSHS 2027 | BSJR | 1 | 5,151.74 | |||||
57 | 52. | INVESCO EXCH TRD SLF IDX FD TR INVSCO BLSH 26 | BSJQ | 1 | 5,214.72 | |||||
58 | 53. | REALTY INCOME CORP COM | O | 14,556.22 | ||||||
59 | 54. | FIDELITY SELECT MED TECHNOLOGY & DEVICES | FSMEX | 12,407.52 | ||||||
60 | 55. | CROWN CASTLE INC COM | CCI | 3,698.82 | ||||||
Portfolio |