Automatically copy over a range of cells if I type the heading of the column

Sntrada

New Member
Joined
Oct 4, 2017
Messages
3
Hi guys,

I am working on an excel sheet for a professor and I really need help. I have 75 columns in excel and each has a different heading which consists of three digits. The headings are all in row 32 of the sheet. All 75 columns have 30 rows of data which have a number in each cell. I am trying to come up with a formula (or something) where I can type the heading of a column (e.g 111) and have excel move the 30 cells which are directly underneath the heading, to a specific spot in the sheet.
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
This works on you typing in the value you are after into a cell, then running the macro with that cell selected.

It will get everything from row 33 down under that heading, cut it and paste below your selected cell.

Code:
Sub movecellsunderactive()

Dim headingstring As String
Dim headingstringaddress As String
Dim colnum As Long

headingstring = ActiveCell.Value
headingstringaddress = ActiveCell.Address
colnum = 1

Do Until colnum = 73
If Cells(32, colnum).Value = headingstring Then
    Cells(32, colnum).Select
    ActiveCell.Offset(1, 0).Select
    Range(Selection, Selection.End(xlDown)).Cut
End If
colnum = colnum + 1
Loop

Range(headingstringaddress).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

Application.CutCopyMode = False

End Sub
 
Last edited:
Upvote 0
Just change to this if in Row 2.

Code:
Sub movecellsunderactive()

Dim headingstring As String
Dim headingstringaddress As String
Dim colnum As Long

headingstring = ActiveCell.Value
headingstringaddress = ActiveCell.Address
colnum = 1

Do Until colnum = 73
If Cells(2, colnum).Value = headingstring Then
    Cells(2, colnum).Select
    ActiveCell.Offset(1, 0).Select
    Range(Selection, Selection.End(xlDown)).Cut
End If
colnum = colnum + 1
Loop

Range(headingstringaddress).Select
ActiveCell.Offset(1, 0).Select
ActiveSheet.Paste

Application.CutCopyMode = False

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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