Kind Support on my Issue.

mike8791

New Member
Joined
Mar 24, 2022
Messages
14
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
  2. Web
Hello Folks,

I have tons of folder in each folder i have 12 excel files Named "1,2,3,4,5,6,7,8,9,10,11,12". I run the code every time and i have been asked to input the three tasks *. I'm looking to slightly modify the code in such:
it just asks for
1- folder location " the one containing amount of 12 ".xl" files.
my code ask to input three tasks*:
1- Task One: the file location i want to open.
2- Task Two: Range Selection on selected workbook to preform the code.
3- Task Three: The name of column i want to paste my results to.

"Essentially no need to modify the functionality of the code but only the three tasks onto one task. it only Just ask for the folder location" The one containing the 12 exel files" then the code should understand file name 1 end-results paste it in destination column A ...... etc ".


Note my destination file is fine with me, i only need to open the 12 xl files automatically and paste the results of each file in the destination file as if
column "A" Data from .xl file 1
column "B" Data from .xl file 2
column "C" Data from .xl file 3
column "D" Data from .xl file 4
column "E" Data from .xl file 5
column "F" Data from .xl file 6
column "G" Data from .xl file 7
column "H" Data from .xl file 8
column "I" Data from .xl file 9
column "J" Data from .xl file 10
column "K" Data from .xl file 11
column "L" Data from .xl file 12

Here is the code:
VBA Code:
Sub CopyRange()
    Dim flder As FileDialog, FileName As String, FileChosen As Integer, srcWB As Workbook, desWS As Worksheet, cnt As Long
    Dim copyRng As Range, desCol As String, i As Long, x As Long
    Set desWS = ThisWorkbook.Sheets("Sheet1")
    Set flder = Application.FileDialog(msoFileDialogFilePicker)
    flder.Title = "Please Select an Excel File"                 ' Here i want it to ask once only
    FileChosen = flder.Show
    FileName = flder.SelectedItems(1)
    Set srcWB = Workbooks.Open(FileName)
    Set copyRng = Application.Range("$D$3:$N$15")   ' keep this
    Application.ScreenUpdating = False
    cnt = copyRng.Columns.Count
    desCol = InputBox("Enter the column letter where you want to paste.")  ' the code should know if file name "1" paste onto column "A"
    If desCol = "" Then Exit Sub
    For i = 1 To copyRng.Rows.Count
        With desWS
            If WorksheetFunction.CountA(.UsedRange) = 0 Then
                .Cells(2, desCol).Resize(cnt) = WorksheetFunction.Transpose(copyRng.Cells(i, 1).Resize(, cnt))
            Else
                .Cells(.Rows.Count, desCol).End(xlUp).Offset(1).Resize(cnt) = WorksheetFunction.Transpose(copyRng.Cells(i, 1).Resize(, cnt))
            End If
        End With
    Next i
    ActiveWorkbook.Close False
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top