Copy values of range immediately below same range excel vba

drluke

Active Member
Joined
Apr 17, 2014
Messages
314
Office Version
  1. 365
Platform
  1. Windows
In my worksheet I have continuous rows with data in D7:D726. I column E I have data from E7:E24. I need to copy the data
in range E7:E24 and autofill the remaining rows in col E (i.e. E25:E726) with that range of values.

The ranges in both col D and the initial range to be copied in col E will never be the same.

So far I have tried this code:
Code:
Range("E7:E" & Range("D" & Rows.Count).End(xlUp).Row).Value = Range("E7:E" & Range("E" & Rows.Count) _
.End(xlUp).Row).Value
The result I'm getting (in E25:E726) is #N/A
Any advise much appreciated.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try:

Code:
    Range("E7:E" & Range("E" & Rows.Count).End(xlUp).Row).AutoFill _
        Destination:=Range("E7:E" & Range("D" & Rows.Count).End(xlUp).Row)
 
Upvote 0
Thank you Dante.
This works, except that for the first value in the range, which is "50" is incrementally increased everytime the range is
copied. So if I have 50,51,52,53,54,55 in my range, instead of copying that it does 51,51,52,53,54,55 etc.
How can I prevent this?
 
Upvote 0
Try
Code:
 Range("E7:E" & Range("E" & Rows.Count).End(xlUp).Row).AutoFill _
        Range("E7:E" & Range("D" & Rows.Count).End(xlUp).Row), xlFillCopy
 
Upvote 0
Thank you Dante.
This works, except that for the first value in the range, which is "50" is incrementally increased everytime the range is
copied. So if I have 50,51,52,53,54,55 in my range, instead of copying that it does 51,51,52,53,54,55 etc.
How can I prevent this?




In this case if you are going to fill a series, then the parameter must be [FONT=&quot]xlFillSeries, try and tell me

Code:
    Range("E7:E" & Range("E" & Rows.Count).End(xlUp).Row).AutoFill _
        Destination:=Range("E7:E" & Range("D" & Rows.Count).End(xlUp).Row), Type:=xlFillSeries
[/FONT]


https://docs.microsoft.com/en-us/office/vba/api/excel.xlautofilltype

[h=1]xlAutoFillType enumeration (Excel)[/h]
  • <time role="presentation" datetime="2017-06-08T00:00:00.000Z" data-article-date-source="ms.date" style="box-sizing: inherit;">
    </time>
  • Specifies how the target range is to be filled, based on the contents of the source range.
[FONT=&quot]
NameValueDescription
xlFillCopy1Copy the values and formats from the source range to the target range, repeating if necessary.
xlFillDays5Extend the names of the days of the week in the source range into the target range. Formats are copied from the source range to the target range, repeating if necessary.
xlFillDefault0Excel determines the values and formats used to fill the target range.
xlFillFormats3Copy only the formats from the source range to the target range, repeating if necessary.
xlFillMonths7Extend the names of the months in the source range into the target range. Formats are copied from the source range to the target range, repeating if necessary.
xlFillSeries2Extend the values in the source range into the target range as a series (for example, '1, 2' is extended as '3, 4, 5'). Formats are copied from the source range to the target range, repeating if necessary.
xlFillValues4Copy only the values from the source range to the target range, repeating if necessary.
xlFillWeekdays6Extend the names of the days of the workweek in the source range into the target range. Formats are copied from the source range to the target range, repeating if necessary.
xlFillYears8Extend the years in the source range into the target range. Formats are copied from the source range to the target range, repeating if necessary.
xlGrowthTrend10Extend the numeric values from the source range into the target range, assuming that the relationships between the numbers in the source range are multiplicative (for example, '1, 2,' is extended as '4, 8, 16', assuming that each number is a result of multiplying the previous number by some value). Formats are copied from the source range to the target range, repeating if necessary.
xlLinearTrend9Extend the numeric values from the source range into the target range, assuming that the relationships between the numbers is additive (for example, '1, 2,' is extended as '3, 4, 5', assuming that each number is a result of adding some value to the previous number). Formats are copied from the source range to the target range, repeating if necessary.
xlFlashFill11Extend the values from the source range into the target range based on the detected pattern of previous user actions, repeating if necessary.

<thead style="box-sizing: inherit;">
</thead><tbody style="box-sizing: inherit;">
</tbody>
[/FONT]
 
Upvote 0
Autofill syntax error

I'm getting a syntax error on this line of code:


Code:
Range("E7:E" & Range("E" & Rows.Count).End(xlUp).Row).AutoFill Destination:=Range("E7:E" & Range("D" & Rows.Count).End(xlUp).Row), xlFillValues


I can't work out what is wrong. Any advice appreciated.
 
Upvote 0
Re: Autofill syntax error

I am not sure exactly what you are trying to do, can you describe in words what you want the code to do rather than just asking to fix code that doesn't work please.
 
Upvote 0
Re: Autofill syntax error

@drluke
Please do not post the same question multiple times. All clarifications, follow-ups, and bumps should be posted back to the original thread.
Per forum rules, posts of a duplicate nature will be locked or deleted (rule 12 here: Forum Rules).

On this occasion I have merged your two threads
 
Upvote 0
Re: Autofill syntax error

I am not sure exactly what you are trying to do, can you describe in words what you want the code to do rather than just asking to fix code that doesn't work please.

In my worksheet I have continuous rows with data in D7:D726. I column E I have data from E7:E24. I need to copy the data
in range E7:E24 and autofill the remaining rows in col E (i.e. E25:E726) with that range of values.
 
Upvote 0
Re: Autofill syntax error

Did you try my suggestion from post#4?
Also what is the error number & message you get with the code you posted?
 
Upvote 0

Forum statistics

Threads
1,214,388
Messages
6,119,229
Members
448,879
Latest member
VanGirl

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