Copy HIDDEN columns to a new workbook

Hi there!

Is there any code which you can help me with to copy HIDDEN COLUMNS to a new 
workbook.

I'm using below codes: (COLUMNS HIDDEN are columns J-K-L)

Sub Copy_With_AutoFilter1()
'Note: This macro use the function LastRow
    Dim My_Range As Range
    Dim CalcMode As Long
    Dim ViewMode As Long
    Dim FilterCriteria As String
    Dim CCount As Long
    Dim WSNew As Worksheet
    Dim sheetName As String
    Dim rng As Range
    Dim WS As Worksheet
    
   Set My_Range = Worksheets("Sheet1").Range("A1:BN" & 
LastRow(Worksheets("Sheet1")))
    My_Range.Parent.Select

    If ActiveWorkbook.ProtectStructure = True Or _
       My_Range.Parent.ProtectContents = True Then
       ActiveWorkbook.Unprotect ("sda")
    End If

    ActiveSheet.Unprotect ("sda")

    'Change ScreenUpdating, Calculation, EnableEvents, ....
    With Application
        CalcMode = .Calculation
        .Calculation = xlCalculationManual
        .ScreenUpdating = False
        .EnableEvents = False
    End With
    ViewMode = ActiveWindow.View
    ActiveWindow.View = xlNormalView
    ActiveSheet.DisplayPageBreaks = False

    'Firstly, remove the AutoFilter
    My_Range.Parent.AutoFilterMode = False
    
    'If you want to filter on a Inputbox value use this
    FilterCriteria = InputBox("What text do you want to filter on?", _
                                   "Enter the filter item.")
    My_Range.autofilter Field:=4, Criteria1:="=" & FilterCriteria

    'Check if there are not more then 8192 areas(limit of areas that Excel 
can copy)
    CCount = 0
    On Error Resume Next
    CCount = 
My_Range.Columns(1).SpecialCells(xlCellTypeVisible).Areas(1).Cells.Count
    On Error GoTo 0
    If CCount = 0 Then
        MsgBox "There are more than 8192 areas:" _
             & vbNewLine & "It is not possible to copy the visible data." _
             & vbNewLine & "Tip: Sort your data before you use this macro.", _
               vbOKOnly, "Copy to worksheet"
    Else
       
        Set WSNew = Workbooks.Add(xlWBATWorksheet).Worksheets(1)
                
        'Ask for the Worksheet name
        sheetName = InputBox("What is the name of the new worksheet?", _
                             "Name the New Sheet")

        On Error Resume Next
        WSNew.Name = sheetName
        If Err.Number > 0 Then
            MsgBox "Change the name of sheet : " & WSNew.Name & _
                 " manually after the macro is ready. The sheet name" & _
                 " you fill in already exists or you use characters" & _
                 " that are not allowed in a sheet name."
            Err.Clear
        End If
        On Error GoTo 0

      
        'Copy/paste the visible data to the new worksheet
        Selection.EntireColumn.Hidden = False
        My_Range.Parent.autofilter.Range.Copy
        With WSNew.Range("A1")
            ' Paste:=8 will copy the columnwidth in Excel 2000 and higher
            ' Remove this line if you use Excel 97
            .PasteSpecial Paste:=8
            .PasteSpecial xlPasteAll
            Application.CutCopyMode = False
            .Select
            ActiveSheet.Protection.AllowEditRanges.Add Title:="Range1", 
Range:=Columns("AS:AX")
        End With

        Selection.autofilter
        ActiveSheet.Protect ("sda")
   
    End If

    'Close AutoFilter
    My_Range.Parent.AutoFilterMode = False

    'Restore ScreenUpdating, Calculation, EnableEvents, ....
    ActiveWindow.View = ViewMode
    If Not WSNew Is Nothing Then WSNew.Select
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
        .Calculation = CalcMode
    End With
 
    My_Range.Parent.Protect Password:="sda"
        
End Sub
0
Utf
1/17/2010 4:33:01 AM
excel.programming 6508 articles. 2 followers. Follow

3 Replies
2536 Views

Similar Articles

[PageSpeed] 38

I kike most of your code.  Here are some comments and the change you are
asking for


1)  It is beeter yo use Thisworkbook rather than Activeworkboook when
refereing to the workbook with the macro.  I also like to give the
worksheet a name as well as the range

From

Set My_Range = Worksheets("Sheet1").Range("A1:BN" &
LastRow(Worksheets("Sheet1")))
My_Range.Parent.Select


ActiveWorkbook.Unprotect ("sda")

ActiveSheet.Unprotect ("sda")

to
Set SourceSht = Worksheets("Sheet1")

Set My_Range = SourceSht.Range("A1:BN" & LastRow(Sourcesht))
SourceSht.Select


ThisworkbookWorkbook.Unprotect ("sda")

Sourcesht.Unprotect ("sda")


2) When you do a copy the source type and the destination type must be
the same type object and you only have to specify the first item in the
destination and not the entire area.  Just like copying manually on the
workbook.

What I mean is the following
Sheets("Sheet1").cells.copy destination:=Sheets("Sheet2").cells

with Sheets("sheet1")
.rows(1:5).copy destination:=.rows(100)
.columns("A:C").copy destination:=.columns("Z")
.Range("A1:D100").copy destination:=.range("T1")
end with


3) When using Autofilter use specialcells (visible) to copy your data. 
You need to unhide the columns before copying

With Sourcesht
.Columns("J:L").hidden = False
Set Copyrange = .Columns("J:L").SpecialCells(xlCellTypeVisible)
Copyrange.Copy Destination:=.Columns("I:J"")
.Columns("J:L").hidden = True
CopyRange.Copy destination:=WSNew.columns("A")
End With


-- 
joel
------------------------------------------------------------------------
joel's Profile: 229
View this thread: http://www.thecodecage.com/forumz/showthread.php?t=170803

[url="http://www.thecodecage.com"]Microsoft Office Help[/url]

0
joel
1/17/2010 7:57:07 AM
Hi Joel,

Thank you for this. However, what I wanted to copy was the entire column 
A:BN with columns J:L hidden in the sourcesheet but should be visible in the 
new worksheet. Any help? THANKS!

"joel" wrote:

> 
> I kike most of your code.  Here are some comments and the change you are
> asking for
> 
> 
> 1)  It is beeter yo use Thisworkbook rather than Activeworkboook when
> refereing to the workbook with the macro.  I also like to give the
> worksheet a name as well as the range
> 
> From
> 
> Set My_Range = Worksheets("Sheet1").Range("A1:BN" &
> LastRow(Worksheets("Sheet1")))
> My_Range.Parent.Select
> 
> 
> ActiveWorkbook.Unprotect ("sda")
> 
> ActiveSheet.Unprotect ("sda")
> 
> to
> Set SourceSht = Worksheets("Sheet1")
> 
> Set My_Range = SourceSht.Range("A1:BN" & LastRow(Sourcesht))
> SourceSht.Select
> 
> 
> ThisworkbookWorkbook.Unprotect ("sda")
> 
> Sourcesht.Unprotect ("sda")
> 
> 
> 2) When you do a copy the source type and the destination type must be
> the same type object and you only have to specify the first item in the
> destination and not the entire area.  Just like copying manually on the
> workbook.
> 
> What I mean is the following
> Sheets("Sheet1").cells.copy destination:=Sheets("Sheet2").cells
> 
> with Sheets("sheet1")
> .rows(1:5).copy destination:=.rows(100)
> .columns("A:C").copy destination:=.columns("Z")
> .Range("A1:D100").copy destination:=.range("T1")
> end with
> 
> 
> 3) When using Autofilter use specialcells (visible) to copy your data. 
> You need to unhide the columns before copying
> 
> With Sourcesht
> .Columns("J:L").hidden = False
> Set Copyrange = .Columns("J:L").SpecialCells(xlCellTypeVisible)
> Copyrange.Copy Destination:=.Columns("I:J"")
> .Columns("J:L").hidden = True
> CopyRange.Copy destination:=WSNew.columns("A")
> End With
> 
> 
> -- 
> joel
> ------------------------------------------------------------------------
> joel's Profile: 229
> View this thread: http://www.thecodecage.com/forumz/showthread.php?t=170803
> 
> [url="http://www.thecodecage.com"]Microsoft Office Help[/url]
> 
> .
> 
0
Utf
1/17/2010 3:22:01 PM
Sorry, but there was too much code in your original message to go through, 
so I thought I would just provide an answer to what you posted in your last 
message (the one I am replying to now) that you can use as a guide for 
modifying your own code.

The following code will copy Columns A:BN from Sheet3 to Sheet5 and the 
columns on Sheet5 will all be visible...

Worksheets("Sheet3").columns("A:BN").Copy Worksheets("Sheet5").Range("A1")
Worksheets("Sheet5").Columns("A:BN").Hidden = False

Note that using the Copy method (as I did in my first statement) copies not 
only the cells contents, but any formatting that they have as well. Also 
note that using this method, does not require selecting or pasting anything 
nor do you have to shut off the "marching ants" (the copy selection border 
indicator).

-- 
Rick (MVP - Excel)


"ch-d" <chd@discussions.microsoft.com> wrote in message 
news:8E0883E0-18E9-4050-AB64-F65AEC119B26@microsoft.com...
> Hi Joel,
>
> Thank you for this. However, what I wanted to copy was the entire column
> A:BN with columns J:L hidden in the sourcesheet but should be visible in 
> the
> new worksheet. Any help? THANKS!
>
> "joel" wrote:
>
>>
>> I kike most of your code.  Here are some comments and the change you are
>> asking for
>>
>>
>> 1)  It is beeter yo use Thisworkbook rather than Activeworkboook when
>> refereing to the workbook with the macro.  I also like to give the
>> worksheet a name as well as the range
>>
>> From
>>
>> Set My_Range = Worksheets("Sheet1").Range("A1:BN" &
>> LastRow(Worksheets("Sheet1")))
>> My_Range.Parent.Select
>>
>>
>> ActiveWorkbook.Unprotect ("sda")
>>
>> ActiveSheet.Unprotect ("sda")
>>
>> to
>> Set SourceSht = Worksheets("Sheet1")
>>
>> Set My_Range = SourceSht.Range("A1:BN" & LastRow(Sourcesht))
>> SourceSht.Select
>>
>>
>> ThisworkbookWorkbook.Unprotect ("sda")
>>
>> Sourcesht.Unprotect ("sda")
>>
>>
>> 2) When you do a copy the source type and the destination type must be
>> the same type object and you only have to specify the first item in the
>> destination and not the entire area.  Just like copying manually on the
>> workbook.
>>
>> What I mean is the following
>> Sheets("Sheet1").cells.copy destination:=Sheets("Sheet2").cells
>>
>> with Sheets("sheet1")
>> .rows(1:5).copy destination:=.rows(100)
>> .columns("A:C").copy destination:=.columns("Z")
>> .Range("A1:D100").copy destination:=.range("T1")
>> end with
>>
>>
>> 3) When using Autofilter use specialcells (visible) to copy your data.
>> You need to unhide the columns before copying
>>
>> With Sourcesht
>> .Columns("J:L").hidden = False
>> Set Copyrange = .Columns("J:L").SpecialCells(xlCellTypeVisible)
>> Copyrange.Copy Destination:=.Columns("I:J"")
>> .Columns("J:L").hidden = True
>> CopyRange.Copy destination:=WSNew.columns("A")
>> End With
>>
>>
>> -- 
>> joel
>> ------------------------------------------------------------------------
>> joel's Profile: 229
>> View this thread: 
>> http://www.thecodecage.com/forumz/showthread.php?t=170803
>>
>> [url="http://www.thecodecage.com"]Microsoft Office Help[/url]
>>
>> .
>> 

0
Rick
1/17/2010 5:03:45 PM
Reply:

Similar Artilces:

DVD Copy Pro for Mac
[b]DVD Copy Pro for Mac[/b] is a DVD copy software that can support D9 to D5 compression. With simple operation, it can save DVD in four different ways including directly burning to DVD disc, saving as DVD folder, copying into DVD media format that can be played by DVD Player directly, and converting as ISO file for easy movie management. Now this cool Mac DVD Copy also supports the latest released Snow Leopard. You can download [b][url=http://www.dvd-copy-mac.net/download/dvd-copy-pro-mac.zip]DVD Copy Pro for Mac[/url][/b] freely right now. [b]More information:[/b][quote]http://www.dvd-...

Import/copy calendar in Outlook 2003
I got a new computer and installed Office 2003, and wanted to move my calendar to the new PC. I created a new data file called Personal Folders from Old PC. I wanted to copy my calendar OVER my current one in Personal Folders, but don't see a way to do so. I can copy my old calendar into the Pesonal Folders, but can't delete the new, empty Calendar. So I have Calendar, and Calendar 1 under my Personal Folders. Any way to just import/copy my reminders/appointments into my new calendar? Thanks for any advice. Ck G'Day Cathy, 1. Use the Folder List 2. Click on the OLD Cal...

Copy info from one workbook to another?
I have a problem I have a workbook with the function i want like a discribe here. The problem is i want to split the workbook but i don`t know how. Is it possible to have a main workbook with information from other workbooks at each worksheet? I have 20 workbooks with information. I would like to have a main workbook with on sheet1 every row from the 20workbooks with category1, on sheet2 every row from the 20workbooks with category2, etc, etc. The information in the 20workbooks in always only on sheet. The Colum in which the data is has no fix end. I go to fill in the rows trough a...

Cant se some columns! Why?
I have a spreadsheet that displays COL A and them col BL-BM-BN etc How do I get to see the cols B to BK I am working with EXCEL 2007 Thanks Either columns B through BK are hidden (most likely), or the Window is frozen and you've scrolled way over to the right, bringing column BL next to A. Assuming they're just hidden, Click on the 2 that identifies row 2 so that the entire row is selected, then On the [HOME] tab, in the CELLS group, pull down the "Format" list and choose Hide and Unhide and click the UNHIDE COLUMNS option. If its a Frozen window thin...

Secondary Copy
Hi, My customer using Great Plains modified report(Primary Copy). Now he wants new report something similar to the modified GP report with very few changes. I tried to copy the modified report and planned to use us a secondary copy. But the report has temp tables, so I am unable to make secondary copy. Can some one help me in how to make a new report something similar to the modified report, where to launch it. Whether it is possible throught VBA & Modifier? Regards Selvakumar.S A report with a temporary table can only be a primary copy. This is because only a primary copy can b...

local copy of mail
How do you store a copy of all your mail on you local computer when using Exchange? You setup an OST/Offline Folders file. Check with your mail admin if they support that configuration. "Brandon Baker" <brandon@discussions.microsoft.com> wrote in message news:epNKuJ19FHA.4004@TK2MSFTNGP14.phx.gbl... > How do you store a copy of all your mail on you local computer when using > Exchange? > ...

Outlook 2000 SP3
How can I copy my mail and calendar to CD so that I can take my received and sent mail history to a new computer with Outlook installed? Thanks. >-----Original Message----- >How can I copy my mail and calendar to CD so that I can >take my received and sent mail history to a new computer >with Outlook installed? Thanks. >. > All your data saves in C:\Documents and Settings\Username\Local Settings\Application Data\Microsoft\Outlook\archive.pst and C:\Documents and Settings\Evgeni\Local Settings\Application Data\Microsoft\Outlook\outlook.pst You can either install instan...

Columns won't Hide!
I'm trying to hide columns in a ss and I get the message, "Cannot Shift Objects off Sheet.". I'm able to hide some columns but Excel seems to reach a limit. Help! You may have something in columns that you don't know about. "Tom" <thomas.hamilton@med.va.gov> wrote in message news:051e01c38d97$7b458e80$a001280a@phx.gbl... > I'm trying to hide columns in a ss and I get the > message, "Cannot Shift Objects off Sheet.". I'm able to > hide some columns but Excel seems to reach a limit. > > Help! >-----Original Mess...

Email trouble with New User in Active Directory
Below is a trail of posts that have been made. My problem has yet to resolved and I need some help quickly. The only other thing I can think of is to reinstall Exchange Server 2003. Hopefully someone will know the answer. Thanks! Subject: Re: Email not Setup when new user created in Active Directory From: "Bryan Hill" <bthill@comcast.net> Sent: 8/15/2004 12:30:21 PM We have other clients that are working fine. Just when we try to set up new ones - it will create the SMTP address but not the X400 address. I tried manually forcing the X400 but it will...

Text to column and paste special transpose
Hi All, I have 1 table like this item_number qty ref 00010-001 3 U34,U36,U43 00013-001 2 U16,U21 12505-001 3 U32,U33,U42 12512-001 3 U5,U6,U27 and 1 want it to become like this item_number qty ref 00010-001 3 U34 00010-001 3 U36 00010-001 3 U43 00013-001 2 U16 00013-001 2 U21 12505-001 3 U32 12505-001 3 U33 12505-001 3 U42 12512-001 3 U5 12512-001 3 U6 12512-001 3 U27 Anybody can help me to program it in macro.. usually i do it manually and have to redo again do to careless. After using Text to Columns on Column C.......comma delimited.........Run the Reorganize macro. Sub ReOrganize...

Error message when hiding columns
Has anyone seen this error message before when trying to hide columns? "Cannot shift objects off sheet." -- valenj ------------------------------------------------------------------------ valenj's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=24087 View this thread: http://www.excelforum.com/showthread.php?threadid=376912 maybe this'll help: XL: "Cannot Shift Objects Off Sheet" Error Hiding Columns http://support.microsoft.com/default.aspx?scid=kb;en-ca;211769 valenj wrote: > > Has anyone seen this error message before whe...

Moving Outlook to a new computer #2
I am trying to move my Outlook 2003 to a new computer and can not see how to move all of my customization with it. For example, the catagories additions I made and all of the rules I set up for lables. Can someone point me to an article that gives you the details? Thanks ...

Copy picture ossice wizard
I have project 2007 standard edition, but the button is not working at all? Any suggestions Hi, The wizard is IMHO useless. Go to Roport, Copy Picture and do without the Wizard what millions have done before the Wizard existed. HTH -- Jan De Messemaeker Microsoft Project Most Valuable Professional +32 495 300 620 For availability check: http://users.online.be/prom-ade/Calendar.pdf "Enrique" <Enrique@discussions.microsoft.com> wrote in message news:72B5AA6C-67AE-468D-B6AE-FF16F52E57BD@microsoft.com... >I have project 2007 standard edition, but the bu...

Log data in a shared workbook
Hi all Is it possible to have a spreadsheet which logs data from anothe without over writing each other's data, even though several colleague are inputting and saving in this shared sheet at different times. Eg. Sheet 1 has various data Sheet 2 - A1,2,3, etc = first save Sheet 3 - B1,2,3, etc = second save Etc. ...for the day Cheers Joe -- Message posted from http://www.ExcelForum.com Joey Would you consider writing to a CSV file? You could use VBA's text file functions to write directly to the file, but the file would still open in Excel. One advantage would be that...

Copy and paste versus copy and insert copied cells
What is the difference between these commands? Try them, it is pretty easy to see the difference -- Regards, Peo Sjoblom "Alana" <Alana@discussions.microsoft.com> wrote in message news:879FED29-5541-41B0-BB2C-7108D42ED593@microsoft.com... > What is the difference between these commands? ...

How do I change the text in a workbook from upper to lower case
Hi Please can anyone help with this one! I have a large workbook that I have created (just with text - no formulas) and I have done it in caps but now want to change all the text to lower case without having to re-type it all. Excel hslp is confusing so can anyone tell me how to do it please Thanks Mike Hi see: http://www.cpearson.com/excel/case.htm -- Regards Frank Kabel Frankfurt, Germany mike wrote: > Hi > > Please can anyone help with this one! > > I have a large workbook that I have created (just with text - no > formulas) and I have done it in caps but now...

Create New Report
Hi there, To set the scene, i'm using web client of 4.0, and i'm not a programmer. Currently, out-of-the-box functionality allows you to run a report called "Quote" which presents the data in a good format, almost good enough to hand to a customer. What I need is this report, but with our logo's embedded, and a few fields added/moved/removed, but i can't figure out how to edit layout options or content options, and I can't even seem to create a similar report from scratch (as they all appear to relate to exisitng XML reports out of the box). I'll be...

subtotal copy and paste
Hi I have used the subtotal option in Excel and this is fine. I have also collasped the list so only the subtotal for each category is visible. However I want to copy and paste this list (just the subtotal) into another sheet When I do this it expands and shows all the results. Is it possible to just copy the visible bit. I have looked in paste special but no luck Cheers Hager On Jan 21, 6:38=A0am, Hager <Ha...@discussions.microsoft.com> wrote: > Hi > > I have used the subtotal option in Excel and this is fine. I have also > collasped the list so only the...

Copy above fails one way, copy below fails another way
I have a table of blood pressure readings that looks something like this: A B C D E 11 12 Averages: 134 83 74 13 R# Date Sys Dia Pul 14 4 8/17/08 138 87 72 15 3 8/15/08 130 84 76 16 2 8/12/08 137 83 70 17 1 8/11/08 129 79 76 Cell A14 contains =A15+1 Cell C12 contains =AVERAGE(C14:C17) Cell D12 contains =AVERAGE(D14:D17) Cell E12 contains =AVERAGE(E14:E17) Every time I take a new reading, I want to add a row to the top of the table, between row 13 (the header) and row 14 (the previous top row). I want to push a...

3D Column Chart #2
How do I create a 3D column chart and have three axis? ...

Business Portal "Copy to Excel" not working in Query pages
Hi, I am using Business Portal 4.0. When browsing through one of the queries pages in Business Portal, i clicked "Copy to Excel" icon. I got an error saying "The Office Web Components (OWC) must be installed to copy results to Excel." at the bottom. I am using Office 2007 on my machine. I came to know that Microsoft Office Web Components will no longer be shipping in Microsoft Office. I tried installing Office 2003 Add-in: Office Web Components from http://www.microsoft.com/downloads/details.aspx?familyid=7287252C-402E-4F72-97A5-E0FD290D4B76&displaylang=en a...

line column Pivot Charts
Access 2003 does not support combined Line/Column Charts, but Excel does. Has the capability been added to Access 2007? Access does support a series displayed as a bars and another series as line. -- Duane Hookom MS Access MVP Help me support UCP http://www.access.hookom.net/UCP/Default.htm "John" <John@discussions.microsoft.com> wrote in message news:A0DD25F6-D99A-44C3-812B-416776BED8AF@microsoft.com... > Access 2003 does not support combined Line/Column Charts, but Excel does. > Has > the capability been added to Access 2007? ...

column headings in numbers vs letters
For some reason all my excel files now display columns as numbers rather than letters. How can I change back to letters? Why are all my old files also now reading in numbered columns? This is a setting of Excel, not of your files. Tools>Options>General, uncheck R1C1 Reference style -- Kind Regards, Niek Otten Microsoft MVP - Excel "garyflood" <garyflood@discussions.microsoft.com> wrote in message news:6870D172-C11D-4FF9-A7D8-48BE89149DF8@microsoft.com... > For some reason all my excel files now display columns as numbers rather > than > letters. How...

Hidden or invisible record in account register
I have a transaction that drove me nuts last weekend causing my checking account to be out of balance. It is a downloaded deposit of $2.00 (an ATM reimbursement fee) in my account. The amount is not visible in the account register so I of course added it manually which meant to Money, it is now in there twice, my manual entry plus it's invisible one. The downloaded transaction is not available for viewing in: *The account register, no matter what filtering I have set. *The Advanced Find menu It is visible in: *The category section for ATM/Bank fees window in the lower right *The Payee se...

Adding a column...very bizarre behavior
I have an MPP file given to me by one of my users. When she tries to add a column to the Gantt Chart view, we get a little screen flicker, then several new columns appear on the view. I don't know what to tell her. It doesn't do this on any other view, and it only does this in this particular MPP. If I open another project file, it doesn't behave this way. Is it possible that this file has just been corrupted somehow? This is a multi-part message in MIME format. ------=_NextPart_000_002F_01CAE16B.B28F3380 Content-Type: text/plain; charset="Windows-1252...