Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9186677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:35:18+00:00 2026-06-17T19:35:18+00:00

I need to copy the excel sheets and make it into one consolidated excel

  • 0

I need to copy the excel sheets and make it into one consolidated excel workbook . After consolidating the worksheet , all files need to move to new folder called “Orginial”.
The folder should be be created where the file is located.

Problem is file will be selected by the user itself

I am using getfilename to get the path from the user

Steps invloving :

Step1 : for example : if user needs to select

C :\my documents\worksheet1.xls
C :\my documents\worksheet2.xls
C :\my documents\worksheet3.xls

step2 :file should be consolidated as worksheet1.xls and

step3: folder should be created in the c:\my documents\original

and all worksheet1, worksheet2,worksheet3 , should move into “original” folder

I have code for consolidting the excelsheets . But i dont know how to create a folder within the path .Please help me

Below is the code

Option Explicit

Sub copyma()

Dim wb(20) As Variant
Dim ws(20) As Variant
Dim lastrow As Variant
Dim lastr(20) As Variant
Dim nextrow As Variant
Dim tempwb As Variant
Dim tempws As Worksheet
Dim tempfile As Variant
Dim fnum As Variant
Dim ws1 As Worksheet
Dim m As Integer
Dim ffiles(20) As Variant
Dim nextlastrow As Variant
Dim lastcopyrow As Variant
Dim lastcopycol As Variant

Set ws1 = Worksheets("sheet1")

fnum = ws1.Range("b3").Value
'selecting temporary files

MsgBox " plz select the temp sheet"
tempfile = Application.GetOpenFilename

Set tempwb = Workbooks.Open(Filename:=tempfile)
Set tempws = tempwb.Worksheets("sheet1")
tempws.Cells.Clear

' sleecting number of files
For m = 1 To fnum
    MsgBox " Please Select " & m & "files"
    ffiles(m) = Application.GetOpenFilename
Next m

' opening the files and copying to the temp sheet
For m = 1 To fnum
    Set wb(m) = Workbooks.Open(Filename:=ffiles(m))
    Set ws(m) = wb(m).Worksheets("sheet")
    ws(m).AutoFilterMode = False
    ' finding the lastrow of the temp sheet
    lastrow = tempws.Range("A" & tempws.Rows.Count).End(xlUp).Row
    lastr(m) = ws(m).Range("A" & ws(m).Rows.Count).End(xlUp).Row
    MsgBox lastr(m)
    nextlastrow = lastrow + 1
    With ws(m)
        lastcopyrow = .Range("A" & .Rows.Count).End(xlUp).Row
        lastcopycol = ws(m).Cells(1, .Columns.Count).End(xlToLeft).Column
        '   lastcol = ws2.Cells(1, .Columns.Count).End(xlToLeft).Column
        If m = 1 Then
            .Range("A1", .Cells(lastcopyrow, lastcopycol)).Copy tempws.Cells(lastrow, 1)
        Else
            .Range("A2", .Cells(lastcopyrow, lastcopycol)).Copy tempws.Cells(nextlastrow, 1)
        End If
    End With
    wb(m).Close
Next m

tempws.Name = "sheet"
tempwb.Save

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:35:19+00:00Added an answer on June 17, 2026 at 7:35 pm
    'Get file path
    Dim outfolder As String
    outfolder = Mid(tmpfile, 1, InStrRev(tmpfile, "\")) & "original"
    'Check if directory exists and create it if it does not
    If Dir(outfolder) = "" Then
    MkDir outfolder
    End If
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a need to copy a worksheet from one workbook into another and
I need to open all Excel files that are in a folder, and copy
I need to copy all *.exe files in some directory to other virtual drive
I need to copy files in one directory to another directory where the lastwritetime
I need to to import some csv files into excel 2010 and create a
i need to copy a set of data from one excel file to another
I have 250 Microsoft Excel (.xls) files, all in a folder. I need to
I have a simple question in excel, I need to copy the content of
I need to copy several files to remote server. for database in `mysql -Bseshow
I need to copy files and directories within a directory. Suppose there is only

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.