VBA Macro - Import data from different excel file for a given value

dan4y

New Member
Joined
Nov 17, 2020
Messages
2
Office Version
  1. 2016
Platform
  1. Windows
Hello guys,
I am very unprepared in everything that means VBA Macros but still I have to find a solution to make my work easier.
banghead.gif

If you don't mind, I'd like to share with you where I got stuck.

In one file I need some data from another file but not all the lines.

In the file where I have to get my data from, I have the following columns:
Code:
row_no.    task    user_id    upload_date    week_no.    year    asin    Marketplace    Keywords_for_upload    GL    PL

I would like, if possible, to import my lines for a value of the "week_no" column that I can add next to the button.

That's what I've managed to do so far, only I can't handle the condition for that "range":
VBA Code:
Sub Get_Data_From_File()
Dim FileToOpen As Variant
Dim OpenBook As Workbook
Application.ScreenUpdating = False
    FileToOpen = "C:\Source.xlsx"
    If FileToOpen <> False Then
        Set OpenBook = Application.Workbooks.Open(FileToOpen)
        OpenBook.Sheets(1).Range("B1:K52").Copy
        ThisWorkbook.Worksheets(2).Range("A1").PasteSpecial xlPasteValues
        OpenBook.Close False
    End If
    Application.ScreenUpdating = True
End Sub

I hope I was quite explicit and thank you in advance for your help.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
What about "Range("E1:E52")" instead "Range("B1:K52")"?
What do you mean "that I can add next to the button"?
 
Upvote 0
I didn't realize I didn't fully explain. I added a button to run the macro. I would like that macro to import my data according to the value I gave for "week_no"
 
Upvote 0

Forum statistics

Threads
1,214,412
Messages
6,119,369
Members
448,888
Latest member
Arle8907

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