Copy heading and name to applicable sheet

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,589
Office Version
  1. 2021
Platform
  1. Windows
I have names in Col O in Sheet2


I need the header in (O1) as well as the name in Col O to be copied to Z1 on the applicable sheet for eg BR1 on Col O as well as the heading to be copied to Sheet BR1 Z1.


it would be appreciated if someone could kindly provide me with code to do this




Book1
O
1Branch Name
2BR1
3BR2
4BR3
5BR4
6BR5
7BR6
8BR7
9BR8
10BR9
11BR10
12BR11
13BR12
Sheet2
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try:
Code:
Sub CopyCells2()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long, rng As Range
    For x = 2 To LastRow Step 7
        Range("W" & x).Resize(3).Copy Sheets(Range("W" & x - 1).Value).Range("AA1")
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks very much for your help, code works perfectly
 
Upvote 0
Do you want the values of column V pasted into column Y of the relevant sheets or added to column Z? If added, do you want them at the beginning or end in column Z?
 
Upvote 0
Thanks for the reply. I need values in column V pasted into column Y of the relevant sheets
 
Upvote 0
Try:
Code:
Sub CopyCells2()
    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long, rng As Range
    For x = 2 To LastRow Step 7
        Range("V" & x).Resize(3).Copy Sheets(Cells(x - 1, "W").Value).Range("Y1")
        Range("W" & x).Resize(3).Copy Sheets(Range("W" & x - 1).Value).Range("Z1")
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
I have another sample file where I need to copy the items in Col V & W to the relevant sheet for eg all the items for BR1 that are 3 rows below it to be copied to sheet BR1 in Col Y1 & Z1, all the items for BR3 that are 3 rows below it to be copied to sheet BR2 in Col Y1 & Z1 etc


I have attached a sample file on Box




https://app.box.com/s/nmh88tv58m36ywvo689qtwho1pcgcf70

Code:
 Sub CopyCells2()
Sheets(1).Select

    Application.ScreenUpdating = False
    Dim LastRow As Long
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Dim x As Long, rng As Range
    For x = 2 To LastRow Step 5
        Range("V" & x).Resize(1).Copy Sheets(Cells(x - 1, "w").Value).Range("Y1")
        Range("W" & x).Resize(1).Copy Sheets(Range("W" & x - 1).Value).Range("Z1")
    Next x
    Application.ScreenUpdating = True
End Sub


Kindly test & amend the code
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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