VBA to select a cell as the variable for a lookup

NateD1

New Member
Joined
Apr 1, 2020
Messages
46
Office Version
  1. 365
Platform
  1. Windows
Hi All,
i have the below code which pulls data from another closed workbook by looking up row no. and col no. and copys data across

can someone help me by changing the code so that the Bold/underlined (36) part of the code is linked to a cell (A1 in the file the data is copied to), which i can then change each time to pull from a different row in the closed work book.

Rich (BB code):
Sub Import()
Application.ScreenUpdating = False
Dim myfilename, strWsName
Dim a As Variant
Dim wb As Workbook
    myfilename = "z:\xxxx\Reports\xxxxx\filename.xlsm" 
    strWsName = ActiveSheet.Range("B1")
Set wb = Workbooks.Open(myfilename)
    With wb.Sheets(strWsName)
        a = .Cells(31, 36).Resize(29) ' Select Row No, col No, number of cells to copy
    End With
    wb.Close False
    Cells(5, 3).Resize(UBound(a)) = a 'Select location to paste to , Row No, col No
      MsgBox "Imported"
      Application.ScreenUpdating = True
 
Last edited by a moderator:

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
VBA Code:
a = .Cells(0,1)
sorry to confuse, but i need the no.36 in the code to be linked to a Cell, so example, when i change cell A1, to 3, the code will change the no.36 to no.3 to lookup different column when pulling data
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,751
Members
448,989
Latest member
mariah3

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