Can't copy hidden columns

mharper90

Board Regular
Joined
May 28, 2013
Messages
117
Office Version
  1. 365
Platform
  1. MacOS
All of my research seems to agree that I should be able to copy the data from hidden columns, but I just can't get it to work. I've tried this exact macro with and without columns E and F being hidden, and it'll only give me the desired result if E and F are not hidden.

Background: ws1 is a roster of all employees at my job and a lot of data pertaining to each. ws2 is a sub-roster of only the employees that fall into a certain category (ws1, column A), and only the data that matters. This macro should find those who meet the ws1, column A criteria to be included on ws2, and populate ws2 with the desired subset of data. Columns E and F are hidden on ws1, but the data is important on ws2.

*Disclaimer, this code is retyped from a printout because the internet does not meet the classification requirements of the network this file exists on. Please excuse minor typos possibly from my retyping error, but point them out if you think they may be the problem for this code not working.

Sub cpypste2()

Dim x As String
Dim ws1 As Worksheet: Set ws1 = Thisworkbook.Sheets("Main Data")
Dim ws2 As Worksheet: Set ws2 = Thisworkbook.Sheets("Figure")
Dim r1 As Range, r2 As Range, r3 As Range, r4 As Range, multiAreaRange As Range​
ws1.Activate​
Set r1 = Range("B:C")
Set r2 = Range("E:F") 'these columns are hidden on ws1
Set r3 = Range("H:H")
Set r4 = Range("N:N")
Set multiAreaRange = Union(r1, r2, r3, r4)

Application.ScreenUpdating = False
x = "NO"

If ws2.Range("A" & Rows.Count).End(xlUp).Row > 2 Then​
ws2.UsedRange.Offset(2).Clear​

If Not IsError(Application.Match(x, ws1.Range("A:A"), 0)) Then

ws1.Range("A3").CurrentRegion.AutoFilter Field:=1, Criteria1:=x
Intersect(ws1.AutoFilter.Range.Offset(1), multiAreaRange).Copy _​
Destination:=ws2.Range("A" & Rows.Count).End(xlUp).Offset(1)​
ws1.AutoFilterMode = False​
End If​
SortGroup2Printout
Application.ScreenUpdating = True
End Sub


 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Try

Insert after ws1.Activate
Code:
 ws1.Columns("E:F").Hidden = False

Insert after End If
Code:
 ws1.Columns("E:F").Hidden = True
 
Last edited:
Upvote 0
Thanks! I'll give that a try as soon as I get back to the office and will let you know.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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