Selecting Dynamic Range in Excel

KiwiGrue

New Member
Joined
Oct 24, 2021
Messages
25
Office Version
  1. 365
Platform
  1. MacOS
I am developing a macro to select financial data from a monthly P&L account which may have differing rows of relevant information each month - see attached example. I need to copy paste to another workbook (see example Financial Data sheet). I am struggling to develop code to identify the information - for example compare Trading Income for the two months with different Income fields.

Any assistance would be appreciated.

Cheers
Form. Limited Example.xlsx
ABCDEFGHIJKLMNO
1Profit and LossProfit and Loss
2Form Limited Form Limited
3For the month ended 31 August 2021For the month ended 30 September 2021Information for each month is always in columns A and B
4
5AccountAug 2021AccountSep 2021
6
7Trading IncomeTrading Income
8ACC Income4,575.00ACC Income5,250.00
9Interest Income250.00Other Revenue175.00
10Other Revenue3,000.00Physiotherapy Income8,775.00
11Physiotherapy Income7,750.00Total Trading Income14,200.00
12Total Trading Income15,575.00
13Cost of Sales
14Cost of SalesPurchases75.00
15Purchases150.00Subcontractors7,650.00
16Subcontractors8,750.00Total Cost of Sales7,725.00
17Total Cost of Sales8,900.00
18Gross Profit6,475.00
19Gross Profit6,675.00
20Other Income
21Operating ExpensesCovid-19 Subsidy6,500.00
22Administration Costs100.00Total Other Income6,500.00
23Advertising125.00
24Bank Fees52.00Operating Expenses
25Cleaning125.00Administration Costs100.00
26Computer & Software Expenses150.00Advertising125.00
27Consulting & Accounting235.00Bank Fees52.00
28Eftpos Expenses50.00Cleaning125.00
29Entertainment - Non deductible12.00Computer & Software Expenses150.00
30Office Expenses35.00Consulting & Accounting235.00
31Rent1,750.00Eftpos Expenses50.00
32Salaries - Shareholder (PAYE deducted)2,500.00General Expenses85.00
33Staff Welfare35.00Office Expenses35.00
34Subscriptions125.00Rent1,750.00
35Training35.00Salaries - Shareholder (PAYE deducted)2,500.00
36Uniforms125.00Subscriptions35.00
37Total Operating Expenses5,454.00Training125.00
38Uniforms35.00
39Net Profit1,221.00Total Operating Expenses5,402.00
40
41Net Profit7,573.00
42
43
Profit and Loss
Cell Formulas
RangeFormula
E11E11=SUM(E8:E10)
B12B12=SUM(B8:B11)
E16,B17E16=SUM(E14:E15)
E18,B19E18=(E11 - E16)
E22E22=E21
B37,E39B37=SUM(B22:B36)
B39B39=((B19 + 0) - B37)
E41E41=((E18 + E22) - E39)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
I have managed to write a couple of VBA routines that can identify the variable cell range (see one below) but I have not been able to use the cell addresses to establish the range to copy and paste (to another worksheet).

Sub UseLookAt()

Dim cell1 As Range
Dim cell2 As Range

Set cell1 = Range("A1:A38").Find("Trading Income", lookat:=xlWhole).Offset(1, 0)
Set cell2 = Range("A1:A38").Find("Total Trading Income", lookat:=xlWhole).Offset(-1, 0)

'Debug.Print cell1.Address

'Debug.Print cell2.Address

End Sub

This sub gives me $A$8 and $A$11 in this example - how do access these then use them to copy A8:B11 for pasting?

Appreciate any assistance

Cheers
 
Upvote 0
Try this
VBA Code:
 Range(cell1, cell2.Offset(0, 1)).Copy Destination:=Range(Output_Location)
 
Upvote 0
Solution
Great it works thanks for your assistance Alex!

Cheers
Alistair
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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