Note that there are some explanatory texts on larger screens.

plurals
  1. POusing a dialog box to select a file and working on it
    primarykey
    data
    text
    <p>i have a code that will compare headers between two worksheets in different workbooks and copy paste data in the main workbook.</p> <pre><code> 'lastCol = Worksheets("Dashboard").Cells(3, Columns.Count).End(xlToLeft).Column lastCol = 15 lastrow = Worksheets("Dashboard").Cells(Rows.Count, 1).End(xlUp).Row Set cmpRng = Range(Cells(1, 1), Cells(3, lastCol)) a = cmpRng i = Cells(Rows.Count, 1).End(xlUp).Row Set Wbk = Workbooks.Open("Z:\RMG\RMG Data Master\Global_HEADCOUNT.xls") Worksheets("GLOBAL_HEADCOUNT").Select Mastcol = Cells(1, Columns.Count).End(xlToLeft).Column j = Cells(Rows.Count, 1).End(xlUp).Row Set mastRng = Range(Cells(1, 1), Cells(1, Mastcol)) b = mastRng For k = 1 To lastCol For n = 1 To Mastcol If UCase(a(3, k)) = UCase(b(1, n)) Then Windows("Global_HEADCOUNT").Activate Worksheets("GLOBAL_HEADCOUNT").Range(Cells(2, n), Cells(j, n)).Copy Windows("Dashboard.xlsm").Activate Worksheets("Dashboard").Select Cells(i + 1, k).PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:=False, Transpose:=False Exit For End If Next Next Call Wbk.Close(False) </code></pre> <p><strong>Now the problem</strong> in this is that every time the file name changes the user has to go in the code and change it, which may lead to problems, so i want to avoid that providing them an alternative to select the files using a dialog box </p> <p><strong>what i know:</strong></p> <p>i have a little knowledge of how to achieve this, </p> <pre><code>'The folder containing the files to be recap'd Set fd = Application.FileDialog(msoFileDialogFilePicker) fd.InitialFileName = "G:\Work\" '&lt;----- Change this to where the files are stored. fd.InitialView = msoFileDialogViewList 'allow multiple file selection fd.AllowMultiSelect = False fd.Filters.Add "Excel Files", "*.xls*" filechosen = fd.Show 'Create a workbook for the recap report Set Master = ThisWorkbook If filechosen = -1 Then </code></pre> <p>but i use the above code for something else and i am having difficulty integrating my code with it... all i am asking is for a little guidance to do it as the result i am trying to achieve is a little different :) ty in advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload