VBA to pull rows from a user selected workbook

Cr864

New Member
Joined
Dec 30, 2021
Messages
21
Office Version
  1. 365
Platform
  1. Windows
Hey everyone,

Im looking for a way to have users be able to click a button to select a file, and within that file if the check numbers listed in Range A7:A100 in the Updated SQL Query 2.0 workbook match a check number in the Column P in the user selected file (for this case, Test.xlsx) then return the entire row and copy it into the Updated SQL Query 2.0 workbook in a sheet named ABC for the purposes of this.

So far, ive found the following code that seems to work to have users to be able to select a file and pull a certain range of data from it. I'm not sure how to look for the numbers in the range and pull back the rows of data from the other sheet though. Any help would be appreciated. Thank you!

VBA Code:
Dim FileToOpen As Variant
Dim OpenBook As Workbook

Application.ScreenUpdating = False
    FileToOpen = Application.GetOpenFilename(Title:="Browse for your File & Import Range", FileFilter:="Excel Files (*.xls*),*xls*")
    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        OpenBook.Sheets(1).Range("A1:AQ20").Copy
        ThisWorkbook.Worksheets("NDC").Range("A2").PasteSpecial xlPasteValues
        OpenBook.Close False
    End If
Application.ScreenUpdating = True



Test.xlsx
P
1CheckNo
2300118
3299284
4299284
5299284
6299284
7299284
8299286
9299284
10299284
11299284
12299284
13299284
14299284
15299284
16299284
17299284
18300294
19299277
20299288
ExcelDestination


Updated SQL Query Sheet 2.0.xlsm
ABCD
6List of checks to be retrieved into tab "BK"Check AmountTotal CheckDifference
70.000.00
80.000.00
90.000.00
100.000.00
110.000.00
120.000.00
130.000.00
140.000.00
Main
Cell Formulas
RangeFormula
C7:C14C7=SUMIF(Combined!$J$2:$J$9958,Main!$A7,Combined!$L$2:$L$9958)
D7:D14D7=B7-C7
Cells with Conditional Formatting
CellConditionCell FormatStop If True
C7:C100Expression=$A7=""textNO
C7:C100Expression=$C7=$B7textNO
C7:C100Expression=$C7<>$B7textNO
 
From what I see, column P doesn't have any list in it. Did you use Stop (my first message yesterday evening) to check that the active worksheet is what it should be?
Bye


I did, it stops on the correct sheet and here is some of the data in column P on that sheet after the stop. Does it matter that there are headers on the columns?

Test.xlsx
P
1CheckNo
2300118
3299284
4299284
5299284
6299284
7299284
8299286
9299284
10299284
11299284
12299284
13299284
ExcelDestination
 
Upvote 0

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
In which vba module did you insert the macro? (all what you read in the header of the vba window)

Bye
 
Upvote 0
In which vba module did you insert the macro? (all what you read in the header of the vba window)

Bye
Hey Anthony,

We're making progress! So, i took the code and inserted it into a new module and just clicked the run button on the module and it is pulling the data! But if i try to insert the same code into a button click sub, it does not pull the data back to the sheet.

What could cause that? But outside of that, the data is pulling now!



Thanks
 
Upvote 0
The macro need to be stored into a "Standard Code Module", not a "Sheet module" or ThisWorkbook module on any other "Class module", or targetting the right data is a little bit more complex.
So leave the code wher it is now, and insert a
VBA Code:
Call MyOtherMacro
into the Button_Click macro.

And of course you may remove all the Debug.Print lines

Bye
 
Upvote 0
The macro need to be stored into a "Standard Code Module", not a "Sheet module" or ThisWorkbook module on any other "Class module", or targetting the right data is a little bit more complex.
So leave the code wher it is now, and insert a
VBA Code:
Call MyOtherMacro
into the Button_Click macro.

And of course you may remove all the Debug.Print lines

Bye

ANTHONY, You're a god. Thank you! Everything works now, thanks for having the patience and taking the time to work through that with me man!!
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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