+ Reply to Thread
Results 1 to 6 of 6

Copy sheet from pat to specific sheet

Hybrid View

martinus1988 Copy sheet from pat to... 02-29-2016, 08:45 AM
WouterM Re: Copy sheet from pat to... 02-29-2016, 09:16 AM
martinus1988 Re: Copy sheet from pat to... 02-29-2016, 09:36 AM
martinus1988 Re: Copy sheet from pat to... 02-29-2016, 02:52 PM
martinus1988 Re: Copy sheet from pat to... 02-29-2016, 02:53 PM
WouterM Re: Copy sheet from pat to... 03-01-2016, 02:40 AM
  1. #1
    Registered User
    Join Date
    10-15-2015
    Location
    NL
    MS-Off Ver
    2013
    Posts
    15

    Post Copy sheet from pat to specific sheet

    Hi all,

    This is a lot to ask but i am really stuck at this point.
    I almost completed my file but I am looking for a solution.
    I have a partlist for every product (named as Aricle 1,2,3,etc). This file contains 1 sheet with like 20 rows of data. I am looking for a way to copy the data from those files to a sheet in this file.

    So: C:\\Test\Partlist\Article1.xlsx must copy to this file, sheet: article 1.


    Path of article - Copy to sheet
    C:\\Test\Partlist\Article1.xlsx - Article 1
    C:\\Test\Partlist\Article2.xlsx - Article 2
    C:\\Test\Partlist\Article3.xlsx - Article 3
    C:\\Test\Partlist\Article4.xlsx - Article 4
    C:\\Test\Partlist\Article5.xlsx - Article 5
    C:\\Test\Partlist\Article6.xlsx - Article 6
    C:\\Test\Partlist\Article7.xlsx - Article 7
    C:\\Test\Partlist\Article8.xlsx - Article 8
    Rules VBA
    Colom A is the path of the file
    Colom B is the sheet (in this file) were it has to copy to.
    When button is pushed the article sheets must renew (do delete and rebuild)
    (Good to know that every file in path has only 1 sheetname is standard)
    All the files are xlsx.


    Can someone help me please.

  2. #2
    Registered User
    Join Date
    02-24-2016
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    92

    Re: Copy sheet from pat to specific sheet

    Hi Martinus,

    You can try this:

    Public Sub UpdateArticelIfo()
        Dim wbkArticle As Workbook
        Dim intRow As Integer
        Dim shtInfo As Worksheet
        Dim strSheet As String
        
        Set shtInfo = ActiveSheet
        intRow = 1
        Do While Not IsEmpty(Cells(intRow, 1))
            shtInfo.Cells(intRow, 2).Select
            strSheet = ActiveCell.Value
            ThisWorkbook.Sheets(strSheet).Select
            ActiveSheet.Cells(1, 1).Select
            ActiveSheet.UsedRange.ClearContents
            ActiveSheet.UsedRange.ClearFormats
            
            Set wbkArticle = Workbooks.Open(shtInfo.Cells(intRow, 1), ReadOnly:=True)
            
            wbkArticle.Sheets(1).Select
            ActiveSheet.UsedRange.Copy
            
            ThisWorkbook.Activate
            ActiveSheet.Paste
            wbkArticle.Saved = True
            wbkArticle.Close savechanges:=False
            intRow = intRow + 1
        Loop
        
    End Sub
    Hoopthis helps,
    WouterM
    The Netherlands

  3. #3
    Registered User
    Join Date
    10-15-2015
    Location
    NL
    MS-Off Ver
    2013
    Posts
    15

    Re: Copy sheet from pat to specific sheet

    Gives an error on ThisWorkbook.Sheets(strSheet).Select
    Should i fill in the path in column A and the sheetname in comlum B?
    Should/Can i use header info?

  4. #4
    Registered User
    Join Date
    10-15-2015
    Location
    NL
    MS-Off Ver
    2013
    Posts
    15

    Re: Copy sheet from pat to specific sheet

    Hi Wouter,

    I fixed my problem for 50%...
    I found a way to do all what i need to do, but i need a loop.
    Do you know how.
    Sub openAndCopyPartlist()
        Dim wbCopy As Workbook
        Dim wsCopy As Worksheet
        Dim rngCopy As Range
        Dim wbPaste As Workbook
        Dim wsPaste As Worksheet
        Dim rngPaste As Range
        
        Set wbCopy = Workbooks.Open(ThisWorkbook.Sheets("Master").Range("H2").Value) 'This is Path location C:\\.....xlsx
        Set wsCopy = wbCopy.Worksheets("Blad1") 'Is name of Sheet1
        Set rngCopy = wsCopy.Range("a1:m100").EntireColumn 'Is range to copy
        Set wbPaste = Workbooks("Voorraad beheer.xlsm") 'Is name of the paste location (workbook name)
        Set wsPaste = wbPaste.Worksheets(ThisWorkbook.Sheets("Master").Range("I2").Value)  'This is Path location for the sheet. like test.
        Set rngPaste = wsPaste.Range("a1")  'Past at cell 1
        
        rngCopy.Copy
        rngPaste.PasteSpecial
        wbCopy.Close savechanges:=False
        
        'now i am looking for a way to do this for the complete list H2 to H99 for sheet names: I2 to I99.
        ' Can someone help me how to make it a loop?
        
    End Sub

  5. #5
    Registered User
    Join Date
    10-15-2015
    Location
    NL
    MS-Off Ver
    2013
    Posts
    15

    Re: Copy sheet from pat to specific sheet

    Hi Wouter,

    I fixed my problem for 50%...
    I found a way to do all what i need to do, but i need a loop.
    Do you know how.
    Sub openAndCopyPartlist()
        Dim wbCopy As Workbook
        Dim wsCopy As Worksheet
        Dim rngCopy As Range
        Dim wbPaste As Workbook
        Dim wsPaste As Worksheet
        Dim rngPaste As Range
        
        Set wbCopy = Workbooks.Open(ThisWorkbook.Sheets("Master").Range("H2").Value) 'This is Path location C:\\.....xlsx
        Set wsCopy = wbCopy.Worksheets("Blad1") 'Is name of Sheet1
        Set rngCopy = wsCopy.Range("a1:m100").EntireColumn 'Is range to copy
        Set wbPaste = Workbooks("Voorraad beheer.xlsm") 'Is name of the paste location (workbook name)
        Set wsPaste = wbPaste.Worksheets(ThisWorkbook.Sheets("Master").Range("I2").Value)  'This is Path location for the sheet. like test.
        Set rngPaste = wsPaste.Range("a1")  'Past at cell 1
        
        rngCopy.Copy
        rngPaste.PasteSpecial
        wbCopy.Close savechanges:=False
        
        'now i am looking for a way to do this for the complete list H2 to H99 for sheet names: I2 to I99.
        ' Can someone help me how to make it a loop?
        
    End Sub

  6. #6
    Registered User
    Join Date
    02-24-2016
    Location
    The Netherlands
    MS-Off Ver
    365
    Posts
    92

    Re: Copy sheet from pat to specific sheet

    Hi Martinus,

    In stead of Range("H2") you can use Cells(2, 8).
    This will give:
    Sub openAndCopyPartlist()
        Dim wbCopy As Workbook
        Dim wsCopy As Worksheet
        Dim rngCopy As Range
        Dim wbPaste As Workbook
        Dim wsPaste As Worksheet
        Dim rngPaste As Range
        Dim intLoop As Integer
        
        Set wbPaste = Workbooks("Voorraad beheer.xlsm") 'Is name of the paste location (workbook name)
        For intLoop = 2 To 99
            Set wbCopy = Workbooks.Open(ThisWorkbook.Sheets("Master").Cells(intLoop, 8).Value) 'This is Path location C:\\.....xlsx
            Set wsCopy = wbCopy.Worksheets("Blad1") 'Is name of Sheet1
            Set rngCopy = wsCopy.Range("a1:m100").EntireColumn 'Is range to copy
            Set wsPaste = wbPaste.Worksheets(ThisWorkbook.Sheets("Master").Cells(intLoop, 9).Value)  'This is Path location for the sheet. like test.
            Set rngPaste = wsPaste.Range("a1")  'Past at cell 1
            
            rngCopy.Copy
            rngPaste.PasteSpecial
            wbCopy.Close savechanges:=False
        Next
    End Sub

+ 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. Replies: 0
    Last Post: 09-16-2015, 01:18 PM
  2. Auto copy specific data from sheet to antoher sheet under few condition
    By Shermaine2010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-17-2014, 04:47 AM
  3. Replies: 6
    Last Post: 10-29-2014, 06:00 AM
  4. [SOLVED] Macro to copy date to specific sheet based on data from another sheet.
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-09-2013, 11:28 AM
  5. Replies: 0
    Last Post: 04-11-2013, 05:33 PM
  6. [SOLVED] Copy and paste data from sheet 2 to sheet 1 based on specific criteria on sheet 1
    By VBADUD in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-05-2012, 04:18 AM
  7. [SOLVED] Copy variable range from sheet to the last row with a specific blank column in new sheet
    By seputus in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-22-2012, 07:29 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