Copy cell from different workbook into another

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
hi all, good morning, hoping you can help :), i have the code below where i am triung to copy cell C1 from Sheet1' (another workbook) and paste into 'ROTA' which is another workbook into cells B2 to B27, but its coming up with an errror, can you help me please :)

Code:
rivate Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim lookuprng As Range

Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Copy("G:\TEAM\ES_Mtr_Tech_Ops\Customer Management Centre\Utilisation\Complex\Rota\Rolling Rota 2017.xlsx")
Set lookuprng = wb2.Sheets("Sheet1").Range("C1")
Set ws1 = wb1.Sheets("ROTA")
ws1.Range("B2:B27").Paste
wb1.Activate
With ws1
i = 7
Do Until .Cells(i, 2) = ""
    Cells(i, 5).Value = Application.VLookup(Cells(i, 2).Value, lookuprng, 2, 0)
    i = i + 1
Loop
End With
End Sub
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
When you run the Macro and get an error, what is the error message and when you run Debug, what line of code is highlighted? Important to solving your issue.
 
Upvote 0
Hi, the error i am getting is Compile error: Method or data member not found, and its highlighting in yellow Private Sub CommandButton1_Click() and also the .Copy part, hope this helps :)
 
Upvote 0
Any help will be greatly appreciated with this, i am still failry new at VBA and still learning :)
 
Upvote 0
Try
Code:
Set wb2 = Workbooks.[COLOR=#ff0000]Open[/COLOR]("G:\TEAM\ES_Mtr_Tech_Ops\Customer Management Centre\Utilisation\Complex\Rota\Rolling Rota 2017.xlsx")
 
Upvote 0
Hi thanks for your help, i have inputted the above code but i get a new error now on the below. The error says 'Run-time error 438, Object doesn't support this property or method. Please can you help me with this? thanks again
Code:
ws1.Range("B2:B27").Paste
 
Upvote 0
This should copy the data, but the vlookup will fail as the range was a single cell
Code:
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim lookuprng As Range

Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open("G:\TEAM\ES_Mtr_Tech_Ops\Customer Management Centre\Utilisation\Complex\Rota\Rolling Rota 2017.xlsx")
wb2.Sheets("Sheet1").Range("C1").Copy wb1.Sheets("ROTA").Range("B2:B27")
wb1.Activate
With wb1.Sheets("ROTA")
i = 7
Do Until .Cells(i, 2) = ""
    .Cells(i, 5).Value = Application.VLookup(.Cells(i, 2).Value, lookuprng, 2, 0)
    i = i + 1
Loop
End With
End Sub
 
Upvote 0
brill that works thank you, i just get 1 error now on the code below that comes up in yellow but i dont knopw what this code is supposed to do. can i delete this?
Code:
.Cells(i, 5).Value = Application.VLookup(.Cells(i, 2).Value, lookuprng, 2, 0)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
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