vba autofill / error range class

Rotating_Potato

New Member
Joined
Oct 9, 2015
Messages
8
Hello,

Desperately in the need of the advise of the forum's experts. I have a code:

Code:
Sub autofill()


Workbooks(file_main).Worksheets("sheet1").Activate
ActiveSheet.Range("R52").End(xlDown).Select
ActiveSheet.Range(Selection, Selection.End(xlToLeft)).Select
Selection.autofill Destination:=ActiveSheet.Range(Range("R52").End(xlUp).Offset(-1, 0), Range("HH52").End(xlDown)), Type:=xlFillDefault


End Sub

The above produces an error 1004 of range class failed. Tried multiple variations of the code, but in the essence followed same logic.

The goal that I want to achieve: find the last cell in column "R", then find the last cell in that row. Finally, select the range and autofill up to the row below the last row. Hopefully this explains what I want... Struggling with it already for hours...Please help.
 
Mike, nice try, but you semi-coded the column in this line ActiveSheet.Range(Cells(Lr, 2), Cells(Lr, LC)).AutoFill Destination:=Selection.
It does the job, but if somebody enter a new column the macro won't work. Correct me if I'm wrong.
I do appreciate a lot your help & effort!
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Hi

Sorry, I am getting confused about the cells you want to autofill.

What is your starting point? Is it the Active cell as you open the sheet?

Then having found the last occupied row, do you want to find the leftmost cell or the rightmost cell in that row?

Do you want to autofill up to row 2 or up to the last row before a blank row?
 
Upvote 0
alright, here's what I got:

a) The line highlighted is x.AutoFill Range(x, Range(Cells(2, "R"), Cells(2, LstCo))). It produces Range of Object Global failed" error.
b) I don't know how to answer this question. Can you explain what u mean?
c) The code provided by you unfortunately doesn't even select the range...

With b) I wanted to know what was in the cells.... numbers, letters, formulas etc.
with c) I should hope it doesn't select anything. You (in most cases) don't need to select a range to work with it (in fact you shouldn't).

Now you need to answer Mike's questions in post #12
 
Upvote 0

Forum statistics

Threads
1,214,932
Messages
6,122,332
Members
449,077
Latest member
jmsotelo

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