Extracting data from a P&L depending on date in the drop down list

Potbellyyemi

New Member
Joined
Mar 16, 2018
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I want to extract data from my P&L budget and forecast (on different tabs in excel) based on a date I select from my drop down list. I basically want to do a variance analysis between the budget and forecast P&L. Both my budget and forecast income statement look like the below in terms of layout

Jan 17 - Mar 17Apr 17 - Jun 17Jul 17 - Sep 17Oct 17 - Dec 17
Establishment costs
<strike></strike>
<strike></strike>100100150200
Salaries
<strike></strike>
<strike></strike>1000100010001000
Sundries
<strike></strike>
<strike></strike>500500500500
Insurance
<strike></strike>
<strike></strike>200200200200
TOTAL P&L1800180018501900

<tbody>
</tbody>


And the variance analysis tab looks like the below with a little drop down list above it. I have already done the drop down list using data validation and the dates in the list look exactly like the above (i.e. Jan17 - Mar 17 etc.) but what formulas can I use to pull the above data in a P&L into the below? vlookup doesn't work as it only pulls data from one specified column, so if I change the date selection in the drop down list, the numbers wont pull.

BudgetForecastVariance
Establishment costs
<strike></strike>
<strike></strike>
Salaries
<strike></strike>
<strike></strike>
Sundries
<strike></strike>
<strike></strike>

<tbody>
</tbody>

I hope this all makes sense. Any help on this will be much appreciated!
Thanks!

 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
in a form youd have a combo box that loaded the date ranges from the sheets.
user picks a date range,
then click a'Start' button and run the macro: MergeData




Code:
Option Explicit
Private mcolCatas As New Collection
Private mcolVals As New Collection
Private mvDate


Public Sub MergeData()
Merge1Date cboBox
'Merge1Date "Apr 17 - Jun 17"


Set mcolCatas = Nothing
Set mcolVals = Nothing
End Sub


Sub Merge1Date(ByVal pvDate)
Const kFOR = "Forcast"
Const kBUD = "Budget"
Dim sht As Worksheet
Dim vShName, vCata, vAmt, vWord
Dim i As Integer


   'fill the variables
mvDate = pvDate
CollectCatas kFOR
CollectCatas kBUD


Sheets.Add
Set sht = ActiveSheet
     
     'post the merged catagories
Range("A2").Select
For Each vWord In mcolCatas
  ActiveCell.Value = vWord
  NextRow
Next


   'post the merge values to new sheet
Range("a1").Value = pvDate
Range("B1").Value = "Budget"
Range("c1").Value = "Forecast"


For Each vWord In mcolVals
   
   BreakupWords vWord, vShName, vCata, vAmt
   
   Select Case vShName
      Case kBUD
         i = 1
      Case kFOR
         i = 2
   End Select
   
   Range("A2").Select
   While ActiveCell.Value <> ""
      If ActiveCell.Value = vCata Then
         ActiveCell.Offset(0, i).Value = vAmt
         GoTo nextVal
      End If
      
      NextRow
   Wend
nextVal:
Next
Set sht = Nothing
End Sub


Private Sub CollectCatas(ByVal pvShtName)
Dim sCata As String
Dim iDteCol As Integer
Dim vVal, vWord


On Error Resume Next


    'find the column with the date
Sheets(pvShtName).Activate
Range("B1").Select
While ActiveCell.Value <> ""
  If ActiveCell.Value = mvDate Then
       iDteCol = ActiveCell.Column
       GoTo skipNext
  End If
  NextCol
Wend


MsgBox mvDate & " date not found in " & pvShtName


skipNext:
   'get the row catagory names
Range("A2").Select
While ActiveCell.Value <> ""
  sCata = ActiveCell.Value
  vVal = ActiveCell.Offset(0, iDteCol - 1).Value
  vWord = pvShtName & ":" & sCata & ":" & vVal
  
  mcolCatas.Add sCata, sCata
  mcolVals.Add vWord
  
  NextRow
Wend
End Sub


Private Sub NextRow()
ActiveCell.Offset(1, 0).Select
End Sub


Private Sub NextCol()
   ActiveCell.Offset(0, 1).Select
End Sub


Private Sub BreakupWords(ByVal pvWord, pvShtName, pvCata, pvAmt)
Dim i As Integer


   i = InStr(pvWord, ":")
   pvShtName = Left(pvWord, i - 1)
   pvWord = Mid(pvWord, i + 1)
   i = InStr(pvWord, ":")
   pvCata = Left(pvWord, i - 1)
   pvAmt = Mid(pvWord, i + 1)
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,681
Members
449,116
Latest member
HypnoFant

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