Copying a dynamic range of cells

Chris_12

New Member
Joined
Nov 22, 2019
Messages
4
Office Version
365, 2019, 2016, 2013, 2010, 2007
Platform
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
 

JLGWhiz

Well-known Member
Joined
Feb 7, 2012
Messages
11,102
Office Version
2013
Platform
Windows
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
 

Forum statistics

Threads
1,078,525
Messages
5,340,974
Members
399,401
Latest member
poiter54

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top