AutoFill Range Syntax with Variable?

JazzSP8

Well-known Member
Joined
Sep 30, 2005
Messages
1,233
Office Version
  1. 365
Platform
  1. Windows
Hey All

Can't seem to work out the correct method for this.

I want to select and then Autofill a set of Formulas but no matter what I try I keep getting an Error :(

This is what I started with that I thought would work;

Code:
Range(Cells(j, "E"), Cells(j, "G")).Select
Selection.AutoFill Destination:=Range("E" & OrderLastRow & ":G" & OrderLastRow)

I've used the variable that way before when filling in a single column but it doesn't seem to like to do it when there is more than one :(

Can someone point me in the right direction?

Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:
Code:
Range(Cells(j, "E"), Cells(j, "G")).AutoFill Destination:=Range("E" & [COLOR=#ff0000][B]j [/B][/COLOR]& ":G" & OrderLastRow)
Note the difference is the part in red (the other thing is I just combined your two rows together - you do not need to select ranges to work with them in VBA, the VBA Recorder is just very literal).
 
Upvote 0
Is this all of your code? Is it only Column E and G that you want to populate or E to G?
 
Upvote 0
Note the difference is the part in red (the other thing is I just combined your two rows together - you do not need to select ranges to work with them in VBA, the VBA Recorder is just very literal).

Ha! - Yes! - That would work better LOL - Thursday Brain is what I'm blaming that one on!

Thanks for the tip on combing the lines as well! :)

Is this all of your code? Is it only Column E and G that you want to populate or E to G?

It is E to G - But Joe4 has pointed out what I was doing wrong now, thanks for the interest though :)
 
Upvote 0
You are welcome!

Yes, the first row in your Autofill always has to be the row you are copying from.

Thanks for the tip on combing the lines as well!
Yes, most anytime you have one row end in "Select" or "Activate", and the next line begins with "Selection" or "ActiveCell", you can combine those two rows together.
Not only does it shorten your code, it also speeds it up (as selecting cells in VBA code slows it down).
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
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