Selection Autofill Range

blackatz4evz

New Member
Joined
Apr 13, 2017
Messages
3
I am having trouble getting the above code to work. I am trying to run a selection autofill macro for two different variables that are stored ranges and am running into errors. Any help would be amazing! :confused:


Code:
  Sub Automation_BOBJ()
    Dim startPointBobjGL As Range
    Dim bobjGLNextCell As Range
    Dim bobjGLLastCell As Range


    Set startPointBobjGL = Range("A3")
    Set bobjGLNextCell = startPointBobjGL.End(xlToRight).Offset(0, 1)
    Set bobjGLLastCell = startPointBobjGL.End(xlToRight).Offset(13, 1)
    bobjGLNextCell.FormulaR1C1 = _
        "=VLOOKUP(RC[-4],R2C2:R27C15,(MONTH(TODAY())+1),0)"
    Selection.AutoFill Destination:=Range(startPointBobjGL, bobjGLLast), Type:=xlFillDefault
    ActiveCell.FormulaR1C1 = "103100335.7"
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Welcome to the Board!

Which line is it erroring on?
Note that if you do not have anything in row 3 after column A, you will get an error, as End(xlToRight) will take you to the last possible column on the sheet, and then .Offset(0,1) will try to move over one more column to the right, which is not possible.
 
Upvote 0
I am getting the error on this line: Selection.AutoFill Destination:=Range(bobjGLOrigCell, bobjGLLast), Type:=xlFillDefault

The error is 1004: Range of object_Global failed

I updated the code so I have something in the column.
 
Upvote 0
Note that you are not selecting anything in your VBA code. So the "Selection" in your code would default to whatever range you have selected before your run this code.
Is that your intention?

It might be better off if you can just describe exactly what you want to happen in plan English, and be sure to mention specific ranges (or better yet, post an example of what your data looks like and what you want to happen).
You cannot upload files to this site. But there are tools you can use to post screen images. They are listed in Section B of this link here: http://www.mrexcel.com/forum/board-a...forum-use.html.
Also, there is a Test Here forum on this board that you can use to test out these tools to make sure they are working correctly before using them in your question.
 
Upvote 0
What I am trying to do in that code is to select the last column and then go one over to the right to a blank column. I then paste a vlookup formula, which is correctly working. Where I am getting stuck is that I want to copy this vlookup formula straight down for 13 columns and fill them with the vlookup formula.
 
Upvote 0
If you can post a sample image of your data, indicating where the data resides (in which cells), I can try to recreate it on my side to see what is going on.
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

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