• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

need macro for excel file

ushaanu

Member
Hi,
Good Morning!
I have an excel file(Sheet-Junk Data) where there are many columns
My Requirement:
I want to keep only few columns like:
customer name ,amount

I am uploading file herewith for your reference. Kindly look into sheet 'Arranged Data' for output. May I request you to help me with VBA solution?
Thanks & Regards,

anu
 

Attachments

  • excel book.xlsx
    248 KB · Views: 6
Hi Anu ,

There are 2 ways of coding this :

1. We see which columns are involved , and use their numbers as static values e.g. Customer Name is column 2 , Machine No. is column 28 , and so on. We copy column 2 , column 28 ,... from the Input data tab.

2. We match the column labels i.e. if the first column on the Output data tab is labelled Customer Name , we look for a match in the header row on the Input data tab , and then copy that column data to the Output data tab.

Both the above methods have their pros and cons.

Which one do you prefer ?

Narayan
 
Here is a less dynamic, but easy to grab code.. you can modify it according to requirement.. :)

Code:
Sub CopySelected()
  Const SrSheet = "Junk Data"
  Const DstSheet = "Arranged Data"
  Sheets(DstSheet).UsedRange.Offset(1).ClearContents
  lR = Sheets(SrSheet).Range("a1").End(xlDown).Row
  With Sheets(DstSheet).Range("a2:j" & lR - 1)
    .Formula = "=HLOOKUP(A$1," & Sheets(SrSheet).Range("a1:aO" & lR).Address(, , , True) & ",ROW()+1,0)"
    .Value = .Value
  End With
End Sub
 
Hi,
Good Morning!
I have an excel file(Sheet-Junk Data) where there are many columns
My Requirement:
I want to keep only few columns like:
customer name ,amount

I am uploading file herewith for your reference. Kindly look into sheet 'Arranged Data' for output. May I request you to help me with VBA solution?
Thanks & Regards,

anu
Hi Anu,
Here is my version. Since you had highlighted the columns to be retained, it was easy to delete all others. Make sure to take a backup before you run this macro.

With Regards
Rudra
 

Attachments

  • excel book(With Macro).xlsm
    79.8 KB · Views: 5
Back
Top