Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel macro to extract specific column

Posted on 2014-04-08
10
Medium Priority
?
1,668 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 53

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 53

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 53

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 53

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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

650 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