Fill down the cell based on the cell value

mayaa_mmm

Board Regular
Joined
Jul 30, 2014
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
I used to download the report from our site, it always gives the report in the below format.

AB C
Class
Subject Maths
Mark details
Semester ISemester IISemester III
103050
5025100
1002040
Class
Subject Science
Mark details
Semester ISemester IISemester III
103050
1002040
5025100

<colgroup><col><col><col></colgroup><tbody>
</tbody>


I want the report in the below format.
Every time i need to remove the rows and manipulate the output to get the below output format.

SubjectSemester ISemester IISemester III
Maths103050
Maths5025100
Maths1002040
Science103050
Science1002040
Science5025100

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>


Kindly help with this issue
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try this with a copy of your workbook.
It may need some tweaking as website data is often not as 'clean' as other data.

Rich (BB code):
Sub Rearrange()
  Dim Data, Results
  Dim ubResults As Long, i As Long, k As Long
  Dim Subj As String
  
  Data = Range("A1", Range("A" & Rows.Count).End(xlUp).Offset(1)).Resize(, 3).Value
  ubResults = Application.Count(Columns("A"))
  ReDim Results(1 To ubResults, 1 To 4)
  k = 1
  Do
    i = i + 1
    If Data(i, 1) = "Subject" Then
      Subj = Data(i, 2)
      i = i + 3
      Do While IsNumeric(Data(i, 1)) And i < UBound(Data, 1)
        Results(k, 1) = Subj
        Results(k, 2) = Data(i, 1)
        Results(k, 3) = Data(i, 2)
        Results(k, 4) = Data(i, 3)
        k = k + 1
        i = i + 1
      Loop
    End If
  Loop Until i >= UBound(Data, 1)
  Range("G2").Resize(ubResults, 4).Value = Results
  Range("G1:J1") = Array("Subject", "Semester I", "Semester II", "Semester III")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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