Cash Forecast Report Commentary Update VBA

Stupid Idiot

New Member
Joined
Sep 26, 2023
Messages
1
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hey,

I just started to learn how to use VBA and i need help.
So i prepare a monthly cashflow forecast report that shows our ending balances for the next 3 month charted against our internal KPI, also there is some commentary in a text box that breaks down the major cash activities for the same period. Is there a way that i can use VBA to take these numbers for the cash activities (which are stored in a different sheet) and combine these figure with provided text templates to produce this commentary?

Thanks in advance
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Short answer is yes. Here's a demo of how you can take values from a sheet & add them to some pre-existing text into a textbox.
With this kind of setup:
Book1
ABCDE
1
2MonthOctoberNovemberDecember
3Budget$1,500$1,500$1,500
4Forecast$1,250$1,600$1,500
5Variance-$250$100$0
6
Sheet2
Cell Formulas
RangeFormula
C5:E5C5=C4-C3


And this code:
VBA Code:
Option Explicit
Sub Write_To_Textbox()
    
    'get month variables, and string variables
    Dim m1 As String, m2 As String, m3 As String
    Dim s1 As String, s2 As String, s3 As String
    m1 = Range("C2")
    m2 = Range("D2")
    m3 = Range("E2")
    
    'Build s1
    If Range("C4") < Range("C3") Then
        s1 = m1 & " is expecting a shortfall of " & Format(Range("C5"), "$0")
    ElseIf Range("C4") > Range("C3") Then
        s1 = "Revenue is expected to exceed budget in " & m1 & " by " & Format(Range("C5"), "$0")
    Else
        s1 = "Revenue is expected to match budget in " & m1
    End If
    
    'Build s2
    If Range("D4") < Range("D3") Then
        s2 = m2 & " is expecting a shortfall of " & Format(Range("D5"), "$0")
    ElseIf Range("D4") > Range("D3") Then
        s2 = "Revenue is expected to exceed budget in " & m2 & " by " & Format(Range("D5"), "$0")
    Else
        s2 = "Revenue is expected to match budget in " & m2
    End If
    
    'Build s3
    If Range("E4") < Range("E3") Then
        s3 = m3 & " is expecting a shortfall of " & Format(Range("E5"), "$0")
    ElseIf Range("E4") > Range("E3") Then
        s3 = "Revenue is expected to exceed budget in " & m3 & " by " & Format(Range("E5"), "$0")
    Else
        s3 = "Revenue is expected to match budget in " & m3
    End If
    
    'Put text into textbox
    With ActiveSheet.Shapes("Textbox 1")
        .TextFrame.Characters.Text = s1 & Chr(10) & s2 & Chr(10) & s3
    End With    
End Sub

You can get this kind of result in an existing textbox on the sheet:
1696045497878.png
 
Upvote 0

Forum statistics

Threads
1,215,139
Messages
6,123,259
Members
449,093
Latest member
Vincent Khandagale

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