+ Reply to Thread
Results 1 to 9 of 9

Need help with VBA code to copy cells for certain values onto new sheet as headings

  1. #1
    Registered User
    Join Date
    05-16-2023
    Location
    Nowhere
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    4

    Need help with VBA code to copy cells for certain values onto new sheet as headings

    Hi all,

    I've been searching online but only found some youtube videos to copy rows from one sheet to another, rather than what I am trying to achieve.

    So I have a table like below:

    table.PNG

    and I want to setup a macro/code that will create headings on a new sheet using cells from column A but only if they have a "y" in column B

    so for example, using the above y's from the above table, the macro should create headings on new sheet like below for those rows with y's:

    'y' headings.PNG

    I hope that makes sense, and someone can help,

    Many thanks,

    Ralphie



    Test file attached below with table and example tab of desired result

    Book1.xlsx
    Attached Images Attached Images
    Last edited by ralphiecifaretto; 05-16-2023 at 09:55 AM.

  2. #2
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,610

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,268

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    Try:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    05-16-2023
    Location
    Nowhere
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    4

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    Quote Originally Posted by Pepe Le Mokko View Post
    Welcome to the forum

    Please attach a sample workbook (not a picture or pasted copy). Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    thank you, I have attached a copy of test file now (Book1.xlsx) with data table and tab with example of desired result

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,268

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    For your file
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    05-16-2023
    Location
    Nowhere
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    4

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    Quote Originally Posted by TMS View Post
    For your file
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    thank you, this seems to work and also updates when the y's are updated

    many thanks for your help

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,268

    Re: Need help with VBA code to copy cells for certain values onto new sheet as headings

    You're welcome.



    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  8. #8
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi, try this !


    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
             
    Sheets.Add Sheets(Sheets.Count)
             [
    A1].RowHeight 25
        With Sheet3
    .[A1].CurrentRegion
            
    .AutoFilter 2"Y"
            
    .Columns(1).Offset(1).Copy
             
    [A1].PasteSpecial , , TrueTrue
            
    .AutoFilter
        End With
            ActiveSheet
    .UsedRange.Resize(6).Borders.Weight 2
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  9. #9
    Registered User
    Join Date
    05-16-2023
    Location
    Nowhere
    MS-Off Ver
    Microsoft 365 Apps for Enterprise
    Posts
    4

    Re: Hi, try this !

    Quote Originally Posted by Marc L View Post

    According to your attachment a VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
             
    Sheets.Add Sheets(Sheets.Count)
             [
    A1].RowHeight 25
        With Sheet3
    .[A1].CurrentRegion
            
    .AutoFilter 2"Y"
            
    .Columns(1).Offset(1).Copy
             
    [A1].PasteSpecial , , TrueTrue
            
    .AutoFilter
        End With
            ActiveSheet
    .UsedRange.Resize(6).Borders.Weight 2
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !
    thank you, this code work's as well, and now I have two options to use

    many thanks for your help as well

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to Copy headings from sheet BR to BR consolidated and copy data from BR1 to BR7
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-08-2023, 03:53 AM
  2. [SOLVED] Create Sheet and Print Headings with the help of a code
    By RAJESH SHAH in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-03-2022, 08:21 AM
  3. [SOLVED] VBA Code to copy values from range of Cells to a Sheet
    By newbie1234 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-15-2020, 01:22 PM
  4. VBA code - copy info from sheet 1 to sheet 2 but NOT COPY BLANK CELLS
    By Yossarian1980 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-14-2017, 06:09 PM
  5. [SOLVED] Macro to Copy data from one sheet to another sheet if column headings match
    By harman83 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-04-2015, 02:40 AM
  6. Replies: 2
    Last Post: 11-21-2013, 10:01 AM
  7. Code to write formula in 2 cells, copy, paste values, repeat next row until end of sheet
    By Oly Steel Man in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-14-2013, 11:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1