+ Reply to Thread
Results 1 to 5 of 5

Need VBA Code to copy multiple column from closed wbs to active sheet

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    11-25-2015
    Location
    bangalore
    MS-Off Ver
    2019
    Posts
    120

    Need VBA Code to copy multiple column from closed wbs to active sheet

    Hi experts

    i have masterfile in one path, i want copy header value from sheet Header and paste column values depends upon requirement into working file.

    assume"C:\Users\Windows 10\Desktop\Orcles\y-23"

    Copy to active sheet from closed wb sheet(Febious_Grand_Data)
    Column A = concate of column F&W from
    Column C=Copy From F
    Column D=Copy From W
    Column E=Copy From X
    Column F=Copy From Y
    Column G=Copy From Z
    Column H=Copy From AA
    Column I=Copy From AC
    Column J=Copy From v
    Column k=Copy From R
    Column M=Copy From AE
    Column Q=Copy From AD
    Column U = Default 1

    find the attachment,thanks for your time
    Attached Files Attached Files
    Last edited by julielara; 04-19-2023 at 09:28 AM.

  2. #2
    Forum Contributor
    Join Date
    11-25-2015
    Location
    bangalore
    MS-Off Ver
    2019
    Posts
    120

    Re: Need VBA Code to copy multiple column from closed wbs to active sheet

    any experts help on this?

  3. #3
    Forum Contributor
    Join Date
    11-25-2015
    Location
    bangalore
    MS-Off Ver
    2019
    Posts
    120

    Re: Need VBA Code to copy multiple column from closed wbs to active sheet

    i tried this code, its not work for me

    Option Explicit
    Sub copycolumn()
    
    Dim wsSource As Worksheet, wsTarget As Worksheet
    Dim wbSource As Workbook, wbTarget As Workbook
    
    Application.ScreenUpdating = False
    
    Set wsSource = wbSource.Sheets("Febious_Grand_Data")
    
    Set wbTarget = Workbooks.Open(Filename:="C:\Users\Master_File.xls")
    Set wsTarget = wbTarget.Sheets("BWS")
    
    wsSource.Range("A:A,D:D,G:G,H:H").Copy
    wsTarget.Paste                                              ' The column A,D,G,H will be copied to column A,B,C,D in wbTarget
    
    ' Save and close wbTarget
    wbTarget.Close True
    
    End Sub

  4. #4
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Need VBA Code to copy multiple column from closed wbs to active sheet

    This is based on your actual data layout, not by the column references in your description in post #1.

    Sub test()
        Dim myDir As String, fn As String, s As String, x, cn As Object, rs As Object
        myDir = "C:\Users\Windows 10\Desktop\Orcles\y-23\": fn = "Master_File.xlsb"
        If Dir(myDir & fn) = "" Then MsgBox "File path is not correct", , myDir & fn: Exit Sub
        s = "'" & myDir & "[" & fn & "]header'!"
        With ThisWorkbook.Sheets("Febious_Grand_Data")
            .[a1].CurrentRegion.ClearContents
            .[a1].FormulaArray = "=max(if(" & s & "1:1<>"""",column(" & s & "1:1)))"
            x = .[a1]
            With .[a1].Resize(, x)
                .Formula = "=" & s & "a1"
                .Value = .Value
            End With
            Set cn = CreateObject("ADODB.Connection")
            Set rs = CreateObject("ADODB.Recordset")
            cn.Open "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & _
                    myDir & fn & ";Extended Properties=""Excel 12.0;HDR=No;"""
            rs.Open "Select F6 & F23, Null, F6, F23, F24, F25, F26, F27, F28, F21, F17, Null, F30, " & _
                    "F21, Null, Null, F30,Null, Null, Null, 1 From `Feliux_Data_Org$A2:AX`;", cn, 3, 3, 1
            .[a2].CopyFromRecordset rs
            Set cn = Nothing: Set rs = Nothing
        End With
    End Sub

  5. #5
    Forum Contributor
    Join Date
    11-25-2015
    Location
    bangalore
    MS-Off Ver
    2019
    Posts
    120

    Re: Need VBA Code to copy multiple column from closed wbs to active sheet

    Thanks experts saved my day legend !!solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Need Help with VBA to run vba code on closed wb from active sheet
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-07-2022, 08:53 AM
  2. [SOLVED] vba code to copy a specific sheet from a closed workbook to the active workbook
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-01-2017, 03:09 AM
  3. [SOLVED] vba code from closed workbook to update active sheet not working as requested
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-22-2017, 09:35 AM
  4. [SOLVED] macro to copy specifc sheet in closed workbook to the active sheet
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-07-2017, 09:53 AM
  5. [SOLVED] macro to copy active sheet to a closed workbook in a specified directory
    By JEAN1972 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-30-2017, 04:43 AM
  6. Search for Value in Closed Workbook and copy Column to Active Sheet Column BE
    By Winon in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 12-19-2011, 12:57 PM
  7. Code to Read/Copy Data from Closed Wb and Return/Paste in Active Wb
    By AlvaroSiza in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-15-2010, 09:26 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1