• 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.

Macro to Copy specific columns from one workbook to another

rdp

New Member
Hi,

I am trying to create a macro to copy specific columns from one sheet to another based on certain condition.
I have dropdown of dates from sheet 1.If I run the macro it will look for the date in the dates column in sheet 1 and will copy and paste specific columns which with that date into another sheet or workbook.

I have tried the following.

Code:
Sub MoveData()

For Each cell In Worksheets("HS").Range("B3:B50") ' Where to look for the date
If cell.Value = "9/17/2018" Then   ' The date
    Range("B4:L50").Select ' What is the range to copy
    Selection.Copy ' Copy it
    Sheets("Jun").Select ' Select the Sheet it applies to
    Range("A1").Select ' Where to paste the data
    ActiveSheet.Paste
    Sheets("HS").Select ' Go back to the templete sheet
    Range("A1").Select
    Application.CutCopyMode = False ' Remove the copy mode
End If
Next ' Move forward to the next

End Sub

Please help me for this.
Thank you!
 
Last edited by a moderator:
Yes.I know the code is working.
But I want to copy and paste only the rows with "9/17/2018" date.And in these rows I only want to copy only specific columns.
Column E to be copied to column B
Column C to be copied to column G
Column G to be copied to column C

And these 3 columns should be copied for rows which satisfy the date condition.

PLEASE HELP.
 
Hi !​
Should be so easy just using an advanced filter if destination columns have same headers names (around 5 codelines)
but as it depends on the worksheets layout (Q: Should any helper guess ? A: No !) so for any further help​
attach at least a before workbook and an after workbook for the expected result …​
 
Yes.But I am not able to figure it out.
I am attaching the source file.
Please let me know.
 

Attachments

  • HS Temp.xlsm.xlsx
    13.4 KB · Views: 8
Last edited by a moderator:
rdp
... hmm?
Is it matter which date-column [A] or [F], where is Your 'keydate'?
Is it ALWAYS fixed eg (17-Sep-2018)?
You would like to
1) copy [QTY] to [FROM]
2) copy [TO] to [STATUS]
3) ... and after that [STATUS] back to [TO]
... really?
Why those #2 and #3?
 
The date should be selected from the date column in HS i.e. column A and not column F.
It is not fixed.The user can select from a drop down or enter manually and based on that date the data should be filtered.
1)QTY TO COLUMN C of the 2nd workbook
2)FROM TO COLUMN G of the 2nd workbook
3)SKU TO COLUMN B of the 2nd workbook

Sorry for the mistake.
 
Here it is.
In this Workbook ,we can enter the date in column K3 or select the date by a dropdown in K3,whatever is convenient.
And then we have a macro that we can click to copy the data from the source file.
 

Attachments

  • Import Temp.xlsx
    13.2 KB · Views: 8
Last edited by a moderator:
So according to your expected result workbook :​
  • K3 is empty
  • Result is empty !
So nothing to do, already done !​
 
Back
Top