+ Reply to Thread
Results 1 to 2 of 2

Copy Range to other workbook on next empty row (only visible rows, include hidden columns)

Hybrid View

  1. #1
    Registered User
    Join Date
    04-18-2013
    Location
    Sweden
    MS-Off Ver
    Excel 2010
    Posts
    37

    Copy Range to other workbook on next empty row (only visible rows, include hidden columns)

    Hi Excel Forum,

    I have a Workbook1 which contains multiple hidden rows & multiple hidden columns. I currently have a code to copy my specified range to Workbook2, but so far I can only either copy everything (i.e. all hidden/non-hidden) or just visible. The problem is that I only want to copy visible rows while still copying all the hidden columns.

    Here is my code so far, which copy/pastes everything in the range. (Please note the top half of the code is not relevant, but I kept it here to avoid misunderstanding.)


    Option Explicit
    
    Sub SaveCopyS()
    'The following code is not relevant for this topic. Please look down below to the next comment.
    
    Sheets("Worksheet1").Protect Password:="aaa", UserInterFaceOnly:=True
    
    If MsgBox("A copy of this worksheet will be created by using the date in cell B4. If a file with this date already exists, it will be overwritten. Are you sure you want to proceed?", vbQuestion + vbYesNo) <> vbYes Then
      
        Exit Sub
      
      End If
      
      MsgBox "This version will now be uploaded to the Team Site."
    
    
    Dim FileName As String
    Dim Path As String
    
    Application.DisplayAlerts = False
    
    
    
    Sheets("W").Copy
        Sheets("Worksheet1").Name = "Static Copy"
        ActiveSheet.UsedRange.Copy
        Range("A1").PasteSpecial Paste:=xlPasteValues
        Path = "C:\PersonalFileLocations\"
        FileName = Range("B4").Value & ".xlsx"
        
        ActiveWorkbook.SaveAs Path & FileName, xlOpenXMLWorkbook, CreateBackup:=False
        
    Application.DisplayAlerts = True
    
    'The code below is relevant for this thread:
    Dim cell As Range
    Application.ScreenUpdating = False
    Range("A9:M48").Select
    Selection.Copy
    Workbooks.Open ("Workbook2.xlsx")
    Sheets("WorksheetA").Activate
    
    ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
    
    Application.CutCopyMode = False
    
    Application.ScreenUpdating = True
    
    
    End Sub

    Thanks for any tips/advice/help!

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525

    Re: Copy Range to other workbook on next empty row (only visible rows, include hidden colu

    You will probably have to loop through the range, for example.

    Sub Button3_Click()
        Dim wb As Workbook, ws As Worksheet
        Dim bk As Workbook, BkSh As Worksheet, LstRw As Long
        Dim Rws As Long, Rng As Range, c As Range
        Set wb = ThisWorkbook
        Set ws = wb.Worksheets("Your Worksheet")
        With ws
            Rws = .Cells(Rows.Count, "A").End(xlUp).Row
            Set Rng = .Range(.Cells(9, 1), .Cells(Rws, 1)).SpecialCells(xlCellTypeVisible)
        End With
        Application.ScreenUpdating = 0
        Set bk = Workbooks.Open("C:\Users\Dave\Downloads\Book3(1).xlsx")
        Set BkSh = bk.Sheets("WorksheetA")
        For Each c In Rng.Cells
            LstRw = BkSh.Cells(Rows.Count, "A").End(xlUp).Row + 1
            c.Range("A1:M1").Copy Destination:=BkSh.Cells(LstRw, 1)
        Next c
        With bk
            .Save
            .Close
        End With
    
    End Sub

+ 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. Replies: 0
    Last Post: 01-15-2014, 05:17 PM
  2. Trying to define a range to include both rows and columns with
    By SamDeets in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-10-2013, 03:47 PM
  3. [SOLVED] can only copy/select visible cells w autofilter on &hidden columns, want to copy all cells
    By JTwrk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-25-2012, 02:12 AM
  4. Copy range from multiple workbooks and include workbook name
    By Barb Reinhardt in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2005, 12:05 PM
  5. [SOLVED] COPY - *want* to include hidden columns
    By Eric in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-26-2005, 09:05 AM

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