+ Reply to Thread
Results 1 to 3 of 3

MACRO copy only unhide cells in range

  1. #1
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    MACRO copy only unhide cells in range

    Good evening to all,

    I have some problems with developing a macro that will copy only unhidden cells in selected range for witch selected range = A7:V?, ? = last full cell in A.

    I have next code:

    Sub CopyINnewWORKBOOK()


    Workbooks.Open Filename:="C:\User\NEW.xlsx"
    On Error Resume Next
    With Workbooks("NEW.xlsx")
    LR = .Sheets("TOTAL").Range("A" & Rows.Count).End(xlUp).Row
    Workbooks("TEST").Sheets("Tabela").Range("A7:V3000").Copy
    Windows("NEW.xlsx").Activate
    Sheets("TOTAL").Range("A" & LR + 1).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    ActiveWorkbook.Close SaveChanges:=1
    End With

    End Sub
    and sub that if finds last full cell in H and selects range:

    Dim icell As Long, LR As Long

    LR = Range("H" & Rows.Count).End(xlUp).Row

    For icell = LR To 1 Step -1
    If Range("H" & icell).Value > 0 Then
    Range("A7:V" & icell).Copy
    Exit For
    End If
    Next icell
    Your help will be much appreciated.

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: MACRO copy only unhide cells in range

    I am assuming that when you say unhidden cells you actually mean unhidden rows. If you copy a range that has hidden rows and paste into another sheet it will only copy the unhidden rows.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    12-13-2012
    Location
    Italy
    MS-Off Ver
    Excel 2010
    Posts
    162

    Re: MACRO copy only unhide cells in range

    My solution

    Workbooks.Open Filename:="your path.xlsx"
    On Error Resume Next
    With Workbooks("your worbook.xlsx")
    LR = .Sheets("ABC").Range("A" & Rows.Count).End(xlUp).Row
    Windows("your original worbook.xlsm").Activate

    LR2 = Range("H" & Rows.Count).End(xlUp).Row

    For icell = LR2 To 1 Step -1
    If Range("H" & icell).Value > 0 Then
    Range("A7:V" & icell).Copy
    Exit For
    End If
    Next icell
    Windows("your worbook.xlsx").Activate
    Sheets("ABC").Range("A" & LR + 1).PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False






    ActiveWorkbook.Close SaveChanges:=1
    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)

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