Copying a dynamic range of cells

Chris_12

New Member
Joined
Nov 22, 2019
Messages
4
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
  6. 2007
Platform
  1. Windows
Hi

I've currently got a data sheet similar to the one below. The data sheet gains multiple rows each month as each new reporting month is added. The column positioning also changes each month. However the title for each range is the same each month.

I want to be able to use VBA to search for the title of each range and then copy the range of data between the two titles, into a seperate blank data sheet.

Any ideas?



Maths scores per person each month

John. Maisie. Hilary.
January. 50. 40. 30
February. 60. 70. 75
March. 75. 90. 40

Art scores per person each month

Maisie. Hilary. John.
January. 100. 92. 100
February. 10. 70. 41
March. 95. 40. 5

English scores per person each month

Maisie. John. Hilary.
January. 30. 60. 100
February. 60. 20. 75
March. 25. 90. 10
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I cannot tell if the data is columnar, but I assume it is..I also assume that each title begins with the name of the class subject, eg. Maths, Art, English, etc. So there would be no need to search for the entire title, just the subject. Based on those assumptions, try this.

Code:
Sub t()
Dim sh As Worksheet, txt As String, fn As Range
txt = InputBox("Enter the subject to find. eg. Maths, Art, etc.", "SUBJECT TO FIND")
Set sh = ActiveSheet
    Set fn = sh.Range("A:A").Find(txt & "*", , xlValues)
        If Not fn Is Nothing Then
            Sheets.Add
            ActiveSheet.Name = txt
            fn.End(xlDown).CurrentRegion.Copy ActiveSheet.Cells(Rows.Count, 1).End(xlUp)(2)
        End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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