Wrong in refering to workbook

kin

Well-known Member
Joined
Jun 26, 2007
Messages
648
Hello

Sub Macro4()


Columns("A:A").Select
Range("A16").Activate
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Range("A1").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[6],'THEMATERIALSBROKEN'Sheet1!R1C1:R250C2,2,FALSE)"
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.NumberFormat = "0"
End Sub


I dont know how to refer to "=VLOOKUP(RC[6],'THEMATERIALSBROKEN'Sheet1

THEMATERIALSBROKEN is another workbook with the vlookup table
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try

Code:
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
 
Upvote 0
ok now but when even if I have the MATERIALSBROKEN open

and run the code another window opens which says UPDATE VALUES: the materialsbroken

while I d like to use the code to make a fast vlookup and not open this window

can you help me??

thanks
 
Upvote 0
I'm not sure if this will work but try

Code:
Application.DisplayAlerts = False
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
Application.DisplayAlerts = True
 
Upvote 0
a message saying run time 1004 error

Autofil method of range class failed

WHat is this ?
 
Upvote 0
Try

Code:
Application.DisplayAlerts = False
With Range("A1:E300")
    .FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
    .NumberFormat = "0"
End With
Application.DisplayAlerts = True
 
Upvote 0
now it makes the autofill but stil the same message and then gets yellow this one

Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault


the whole code is


Sub Macro4()



Columns("A:A").Select
Range("A1").Activate
Application.CutCopyMode = False
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Selection.Insert Shift:=xlToRight
Range("A1").Select

Application.DisplayAlerts = False
With Range("A1:E300")
.FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
.NumberFormat = "0"
End With
Application.DisplayAlerts = True


'Application.DisplayAlerts = False
'ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
'Application.DisplayAlerts = True

Range("A1").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.NumberFormat = "0"




End Sub
 
Upvote 0
Delete this code

'Application.DisplayAlerts = False
'ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[6],'[THEMATERIALSBROKEN]Sheet1'!R1C1:R250C2,2,FALSE)"
'Application.DisplayAlerts = True

Range("A1").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.AutoFill Destination:=Range("A1:E300"), Type:=xlFillDefault
Range("A1:E300").Select
Selection.NumberFormat = "0"
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,692
Members
448,979
Latest member
DET4492

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