Can I edit this macro to only copy i=cells that are not hidden?

tonywatsonhelp

Well-known Member
Joined
Feb 24, 2014
Messages
3,194
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Hi Everyone,

I have this macro that works great but it copys cells with values even if the row is hidden,

is it possible to copy only cells that are visiable?

If not, or if its easier a macro that clear contents of all hidden rows would be fine

Thanks

Tony

Code:
Sub Move_Values1()
Application.ScreenUpdating = False
Sheets("Test1").Select
LastRow1 = Sheets("Test1").Cells(Rows.Count, "A").End(xlUp).Row
If LastRow1 < 10 Then
Exit Sub
End If


Sheets("Test1").Range("J10", "SW" & LastRow1).SpecialCells(xlCellTypeConstants, 23).Select
 For Each Area In Selection.Areas
 AddS = Area.Address

 Sheets("Test2").Range(AddS).Value = Area.Value
 Next Area

End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Tony,

Try the following:

Code:
Sub Move_Values1()
    Dim lastrow1            As Long
    Dim area                As Range
    Dim AddS                As String
        
    Application.ScreenUpdating = False
    Sheets("Test1").Select
    lastrow1 = Sheets("Test1").Cells(Rows.Count, "A").End(xlUp).Row
    
    If lastrow1 < 10 Then
        Exit Sub
    End If




    Sheets("Test1").Range("J10", "SW" & lastrow1).SpecialCells(xlVisible).Select


    For Each area In Selection
        If Len(area) > 0 Then
            AddS = area.Address
            Sheets("Test2").Range(AddS).Value = area.Value
        End If
    Next area


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,856
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top