I am trying to create a cash flow workbook. Currently, I am working on a projections part of my idea.
Basically, the user must plan ahead funds to be spent in the future.
My workbook has the following sheets:
Cash Flow - in this sheet, Range (G18:L41) the user enters projections (in green cells). In cell P10 there is an installment picker. Selected installment affects G15:L15 values (months).
The idea is for a user to enter projections for a selected month, then click on Copy CF Data.
CPP Raw - here is where data is stored from the Cash Flow sheet. The user can retrieve data from CPP Raw by clicking on Retrieve CF Data in the Cash Flow worksheet.
ParCF - this is a parameters worksheet, where I defined named ranges, etc.
Here is an example of the idea:
1. the user creates the projection for Sep21. Then stores data in CPP Raw by clicking on Copy CF Data.
2. the user wants to change the projections. To do so, the user clicks on Retrieve CF Data.
3. the user gets old values. Replaces them with the new.
4. the user clicks on Copy CF Data again.
I have a problem with my code, as follows:
My code works fine for the first-time entry of data.
For later changes, my code keeps adding the data to the subsequent rows. Basically, I want to replace the data, not to continue adding rows.
Here is the file (it has multiple worksheets within the workbook):
Basically, the user must plan ahead funds to be spent in the future.
My workbook has the following sheets:
Cash Flow - in this sheet, Range (G18:L41) the user enters projections (in green cells). In cell P10 there is an installment picker. Selected installment affects G15:L15 values (months).
The idea is for a user to enter projections for a selected month, then click on Copy CF Data.
CPP Raw - here is where data is stored from the Cash Flow sheet. The user can retrieve data from CPP Raw by clicking on Retrieve CF Data in the Cash Flow worksheet.
ParCF - this is a parameters worksheet, where I defined named ranges, etc.
Here is an example of the idea:
1. the user creates the projection for Sep21. Then stores data in CPP Raw by clicking on Copy CF Data.
2. the user wants to change the projections. To do so, the user clicks on Retrieve CF Data.
3. the user gets old values. Replaces them with the new.
4. the user clicks on Copy CF Data again.
I have a problem with my code, as follows:
VBA Code:
Sub CF_cpData()
Dim rng As Range, trgtCell As Range, src As Worksheet, trgt As Worksheet
Set src = Worksheets("Cash Flow")
Set trgt = Worksheets("CPP Raw")
Application.ScreenUpdating = False
With src
For Each rng In src.Range("G15:L15")
Set trgtCell = trgt.Rows(1).Find(rng.Value, LookIn:=xlValues, lookat:=xlWhole)
If Not trgtCell Is Nothing Then
.Range(rng.Offset(1), .Cells(.Rows.Count, rng.Column).End(xlUp)).Copy
With trgt
'Here is where I need the code:
.Range(Split(trgtCell.Address, "$")(1) & .Cells(.Rows.Count, trgtCell.Column).End(xlUp).Row + 1).PasteSpecial xlPasteValues
End With
End If
Next rng
End With
Application.ScreenUpdating = True
End Sub
My code works fine for the first-time entry of data.
For later changes, my code keeps adding the data to the subsequent rows. Basically, I want to replace the data, not to continue adding rows.
Here is the file (it has multiple worksheets within the workbook):