Range question

Benic

New Member
Joined
Aug 2, 2013
Messages
35
Hello,

I have code which works:

Code:
Sub CopyVLOOKUP() '
' CopyVLOOKUP Macro
    
Range("C10").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],brutto_cijene!R5C2:R65536C14,2,FALSE),"""")"
    Range("C10").Select
    Selection.AutoFill Destination:=Range("C10:C300")
    Range("C10:C300").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False
End Sub

I would like to manually change C10 and C300 values like C10 = Raspon1, C300 = Raspon2. I tried like this:

Code:
Sub CopyVLOOKUP() '
' CopyVLOOKUP Macro
'
    Dim Raspon1 As Integer
    Dim Raspon2 As Integer
    
    Raspon1 = 10
    Raspon2 = 300
    
    Range("Raspon1").Select
    ActiveCell.FormulaR1C1 = _
        "=IFERROR(VLOOKUP(RC[-1],brutto_cijene!R5C2:R65536C14,2,FALSE),"""")"
    Range("Raspon1").Select
    Selection.AutoFill Destination:=Range("Raspon1:Raspon2")
    Range("Raspon1:Raspon2").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Application.CutCopyMode = False

but I get error message.

Run time error "1004"
Method "Range" of object _Global failed

thanks in advance,
 
How is "Private Sub Workbook()" called?
Is it supposed to be an Event Procedure that is called automatically upon some action happening?
If so, I don't think there is one called "Workbook". Perhaps you are looking for "Workbook_Open", which runs when the workbook is first opened.


If it is just supposed to be a standard procedure, you should not use reserved word to name procedures (like "Workbook"), functions, or variables.
The conflicts can confuse Access VBA.
 
Upvote 0

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

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