?
Solved

Excel macro to extract specific column

Posted on 2014-04-08
10
Medium Priority
?
1,506 Views
Last Modified: 2014-04-08
Hello EE,

I have a spreadsheet that have 15 columns.  Is it possible to extract 2 specific columns and place the data into a new tab in the same workbook?  I have attached my sample data.  I have the data in a tab called Data.  I want a new tab created called Expected.

Thanks,
testme.xlsx
0
Comment
Question by:fb1990
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 8

Expert Comment

by:Naresh Patel
ID: 39985623
Do u need macro for this or want to do it manually?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39985650
Hi,

pls try

Sub Macro()
    Set DestSht = Sheets.Add(After:=Sheets(Sheets.Count))
    DestSht.Name = "Expected1"
    Sheets("Data").Columns("O:O").Copy Destination:=DestSht.Range("A1")
    Sheets("Data").Columns("C:C").Copy Destination:=DestSht.Range("B1")
    Application.CutCopyMode = False
    
End Sub

Open in new window

Regards
0
 
LVL 1

Author Comment

by:fb1990
ID: 39985728
I need a macro to automate it
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:fb1990
ID: 39985737
Hello Rgonzo1971,

Your suggestion worked well.  Is there a way to add filter column J and only pull records where the value is greater than zero?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39985837
Hi,

pls try

Sub Macro2()
    Range("J1").AutoFilter
    ActiveSheet.UsedRange.AutoFilter Field:=10, Criteria1:=">0"
    Set DestSht = Sheets.Add(After:=Sheets(Sheets.Count))
    DestSht.Name = "Expected1"
    Sheets("Data").Columns("O:O").Copy Destination:=DestSht.Range("A1")
    Sheets("Data").Columns("C:C").Copy Destination:=DestSht.Range("B1")
    Application.CutCopyMode = False
    Sheets("Data").Range("J1").AutoFilter
End Sub

Open in new window

Regards
0
 
LVL 1

Author Comment

by:fb1990
ID: 39986211
Hello Rgonzo1971,

I tried the last code and i am getting a runtime error

Thanks
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 39986235
Where does the code stop?
0
 
LVL 1

Author Comment

by:fb1990
ID: 39986398
This is the image

Doc1.docx
0
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 39986673
Hi,

try this

Sub Macro2()
    Sheets("Data").Range("J1").AutoFilter
    Sheets("Data").UsedRange.AutoFilter Field:=10, Criteria1:=">0"
    Set DestSht = Sheets.Add(After:=Sheets(Sheets.Count))
    DestSht.Name = "Expected1"
    Sheets("Data").Columns("O:O").Copy Destination:=DestSht.Range("A1")
    Sheets("Data").Columns("C:C").Copy Destination:=DestSht.Range("B1")
    Application.CutCopyMode = False
    Sheets("Data").Range("J1").AutoFilter
End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:fb1990
ID: 39987652
Thank you so much for your help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question