+ Reply to Thread
Results 1 to 4 of 4

copy to empty column starts with column E

Hybrid View

  1. #1
    Registered User
    Join Date
    06-26-2014
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    16

    Post copy to empty column starts with column E

    Good day to all,
    im newbie on this vba and excel
    i have this problem and search through the internet and try to compile but cant get fix the code the exact way i want


    i like to paste a manually selected columns from sheet1 and paste to range E5 if not empty

    an example is like this
    i manually select a range of columns and if i press a command button it the range of column will be copied to sheet2 range E5 if not empty.

    my code
    Sub Button5_Click()
        Dim LastColumn As Integer
        Dim shFO, sh4 As Worksheet
        
        shFO = Worksheets("Final Output")
        sh4 = Worksheets("Sheet4")
        
        With shFO
            LastColumn = .Find(What:="*", After:=.Cells(5), Lookat:=xlPart, _
            LookIn:=xlFormulas, SearchOrder:=xlByColumns, SearchDirection:=xlPrevious, _
            MatchCase:=False).Column
            
            sh4.Activate
            Selection.Copy destination:=LastColumn
        End With
    End Sub

  2. #2
    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,198

    Re: copy to empty column starts with column E

    Hi, dragavs,

    if you are working with Worksheets and Ranges/Cells you would need to use Set in order to build an object to these. I´m assuming you would like to add further information to the next available column:
    Sub Button5_Click()
        Dim rngToCopy As Range
        Dim shFO As Worksheet
        
        Set shFO = Worksheets("Final Output")
        
        With shFO
          Set rngToCopy = .Cells(5, Columns.Count).End(xlToLeft).Offset(0, 1)
          Selection.Copy Destination:=rngToCopy
        End With
        
        Set rngToCopy = Nothing
        Set shFO = Nothing
    End Sub
    Ciao,
    Holger
    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

  3. #3
    Registered User
    Join Date
    06-26-2014
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    16

    Re: copy to empty column starts with column E

    thank you for the quick answer HaHoBe the code is perfect.

  4. #4
    Registered User
    Join Date
    06-26-2014
    Location
    Philippines
    MS-Off Ver
    2007
    Posts
    16

    Post Re: copy to empty column starts with column E

    final code
        Dim rngToCopy As Range
        Dim shFO As Worksheet
        
        Set shFO = Worksheets("Final Output")
        
        With shFO
          Set rngToCopy = .Cells(9, Columns.Count).End(xlToLeft).Offset(0, 1)
          Selection.Copy destination:=rngToCopy
          rngToCopy.Columns.Group
        End With
        
        Set rngToCopy = Nothing
        Set shFO = Nothing

    i have this code and i like this to add a code that will group the rngToCopy

+ 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 find the empty cell in a column and copy a adjacent row to another column.
    By naga in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-18-2013, 07:44 AM
  2. copy & paste last column from pivot table to next empty column
    By kitrak2 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-12-2013, 06:57 PM
  3. [SOLVED] Copy Column as Selection and Insert to the next Empty Column MACRO
    By kaurka in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 04-22-2013, 12:50 PM
  4. Replies: 4
    Last Post: 08-31-2010, 10:48 PM
  5. Copy a formula to cells in column A which don't have an empty cell in column B
    By floep in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-24-2006, 04:57 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