Copying multiple columns

hedonman

New Member
Joined
Apr 25, 2011
Messages
11
Hello Mr.Excel Board!

This is my first post and apologize if i am missing any formalities. I am using Office Excel 2010. Below is code for what I am trying to do. I am so close but stuck.

I am trying to extract specific columns from a Workbook with many Worksheets into another NEW workbook on One single worksheet.

Code:
Sub SearchBurnerList()

    Dim fileName As String: fileName = "C:\Users\...\Burner List.xls"
    Dim ws As Worksheet
    Dim wb As Workbook
    Dim lastRow
        lastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    Set wb = Workbooks.Open(fileName)

    For Each ws In wb.Worksheets
        ws.Range("A1", "B2").Copy _
            ThisWorkbook.Sheets("SearchBook").Range("A" & Rows.Count).End(xlUp).Offset(1)
        'ws.Range(Columns(1), Columns(2)).Select
       ' Selection.Copy ThisWorkbook.Sheets("SearchBook").Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next ws

    'wb.Close False

End Sub

My problem is at the moment is at the ws.Range().Copy... i don't know what to fill in there to get the columns. Because i am using the COPY method, does that change the parameters?

Thank you Very much
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Welcome to the Board!

If you are just trying to select the first two columns, this should worK:
Code:
    ws.Columns("A:B").Select
 
Upvote 0
thanks for the reply joe4.

Acutally what i am trying to do is; Get the columns from A,B,C, H, J. But only after the 2nd row. I should of put A2 etc etc.

Would the convention work?:


ws.Columns("A2:B2", "H2", "J2"). Copy _</pre>
 
Upvote 0
Wouldn't it just be easier to copy the whole column and then delete the first row after the copy? Then you don't need to worry about finding the ending row.
 
Upvote 0
ws.Columns("A:B").Select

I just tried taking the whole columns. But i get an error:
Application defined or object defined error. Run-Time Error 1004


My Goal is to Open A workbook and take every worksheet and put that into my current workbook's single worksheet.

Does it look like this code does that?

Man im so stumped
 
Upvote 0
try this
PHP:
ws.Range("A2:B,H2:J"). Copy

Just tried it, I still get the same 1004 error. VBA auto corrected the space after the Copy. i added the "_" after the copy for the paste location. Ran it and debug'd the crash at this line.

how exactly does Range work? I heard you can do this?
Code:
ws.Range(Columns(A),Columns(B)).Copy _ ???

Additionally how can you print a message to the screen? I did a counter in my for loop. i want to count how many worksheets are being cycled through.
 
Upvote 0
I still get the same 1004 error
Sounds like it is not recognizing "ws" as a valid range name.
Currently, how is "ws" declared and value set?
 
Upvote 0
I declared it at the top after Sub.

Dim ws As Worksheet

Code:
Also if i do this:
Dim count
        count = 1
Print count

does that work?
 
Upvote 0
What exactly are you trying to do with the code you just posted, and how does it relate to your original question?

It would probably be helpful if you posted you entire current code that you are getting the error on. If I get some time later today, I may see if I can recreate your situation.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,761
Members
452,940
Latest member
rootytrip

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