+ Reply to Thread
Results 1 to 11 of 11

Duplicating entire column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    05-05-2020
    Location
    Germany
    MS-Off Ver
    2013
    Posts
    100

    Duplicating entire column

    Hi

    how do you duplicate the last column?

    and why doesn't this code work?

    Dim LastColumn As Long
    
    LastColumn = Sheets("Tabelle1").Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    Range(LastColumn).EntireColumn.Copy Range(LastColumn + 1)
    p.s. I can't change this part
    LastColumn = Sheets("Tabelle1").Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    because it's part of another code.

  2. #2
    Valued Forum Contributor
    Join Date
    10-12-2021
    Location
    CT
    MS-Off Ver
    365
    Posts
    462

    Re: Duplicating entire column

    Range(LastColumn).EntireColumn.Copy 
    
    Range(LastColumn).offset(0,1).xlpastespecial
    Last edited by carlmon; 09-19-2022 at 03:50 PM.

  3. #3
    Forum Contributor
    Join Date
    05-05-2020
    Location
    Germany
    MS-Off Ver
    2013
    Posts
    100

    Re: Duplicating entire column

    Quote Originally Posted by carlmon View Post
    Range(LastColumn).EntireColumn.Copy 
    
    Range(LastColumn).offset(0,1).xlpastespecial
    Thanks, but it doesn't work. and the first row is highlighted.

  4. #4
    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,945

    Re: Duplicating entire column

    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    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


  5. #5
    Forum Contributor
    Join Date
    05-05-2020
    Location
    Germany
    MS-Off Ver
    2013
    Posts
    100

    Re: Duplicating entire column

    Quote Originally Posted by TMS View Post
    Fast answers need visual help. Please read the yellow banner at the top of this page on how to attach a file.
    Yeah sorry. it says that the range for the '_global' is wrong.

  6. #6
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Duplicating entire column

    Hi (T_T),

    what about
    Dim LastColumn As Long
    
    With Sheets("Tabelle1")
      LastColumn = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
      .Cells(1, LastColumn).EntireColumn.Copy Cells(1, Columns.Count).End(xlToLeft).Offset(0, 1)
    End With
    and why doesn't this code work?
    A range expects to get information about the column letter and a row or a full column. VBA relies on certain rules that have to be followed. In your case both range and cells should not only be addressed by a column number.

    HTH
    Holger
    Last edited by HaHoBe; 09-19-2022 at 05:17 PM. Reason: added With clause to code
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  7. #7
    Forum Contributor
    Join Date
    05-05-2020
    Location
    Germany
    MS-Off Ver
    2013
    Posts
    100

    Re: Duplicating entire column

    Quote Originally Posted by HaHoBe View Post


    Dim LastColumn As Long
    
    With Sheets("Tabelle1")
      LastColumn = .Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column
    could you explain the "*"?

  8. #8
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Duplicating entire column

    Hi (T_T),

    if you pass numeric values to the range it should be like
    Range(LastColumn & ":" & LastColumn)
    but this will work with the given row indicated.

    You may use
    Columns(LastColumn)
    if you want to work with a numeric value.

    HTH,
    Hoiger

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

    Cool Hi, try this ...


    For smart worksheet only :

    PHP Code: 
    Sub Demo1()
        
    With Tabelle1.UsedRange.Columns
            
    .Item(.Count).Copy .Item(.Count 1)
        
    End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon ? Add Reputation ? !

  10. #10
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2019 | 2021
    Posts
    15,023

    Re: Duplicating entire column

    Similar...Data starting in A1

    Sub J3v16()
    With Cells(1).CurrentRegion
        .Columns(.Columns.Count).Copy .Columns(.Columns.Count + 1)
    End With
    End Sub
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  11. #11
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Duplicating entire column

    (Hi T_T),

    code will search all the cells on your sheet and return the column of the last cell with any sort of value stored in it (the asterisk is a wildcard meaning any content) - but code was part of your first post of this thread...

    HTH,
    Holger

+ 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. Duplicating a Row or Column
    By Zombra in forum Excel General
    Replies: 8
    Last Post: 05-03-2015, 08:15 PM
  2. Replies: 0
    Last Post: 06-26-2013, 05:58 PM
  3. Duplicating Values in a column
    By fredaldous in forum Excel General
    Replies: 3
    Last Post: 11-09-2012, 07:22 AM
  4. [SOLVED] Duplicating values in the same column
    By sparkboom in forum Excel General
    Replies: 1
    Last Post: 09-20-2012, 04:14 PM
  5. Formula for duplicating a column?
    By jd8386 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-09-2012, 10:34 AM
  6. duplicating dates from one column to another
    By tinainsuffolk in forum Excel General
    Replies: 7
    Last Post: 04-19-2011, 11:40 AM
  7. Duplicating Values in a column
    By JoshD75 in forum Excel General
    Replies: 2
    Last Post: 03-05-2011, 07:27 PM

Tags for this Thread

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