VBA AutoDrag Help Please

NataliaMSN

New Member
Joined
Mar 16, 2011
Messages
5
Hello I heard this forum is the best .
I was having some sytax issues with a formula in VBA.
I was stuck on the portion of my code with the range of my autodrag function . . .

I have a formula that I want to auto drag down to the row where my data stops in Column A.
My formula is starting in D3 and I want it to autodrag using Column A as a reference to drag.
I need to do it that way because B and C do not necessary have data in every row thats why I need to use A as the reference.
I was Attempting to use the "AutoFill Destination:" VBA Function but I am confused as to how to specify my range after that can someone help me out please.

Sorry, I am relatively new to VBA.

I am using Excel 2010.
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

sage_bob

New Member
Joined
Apr 27, 2005
Messages
28
Hi,
This doesn't use the AutoFil function but I find it a useful thing to know.
Code:
Range("D3").Resize(Range("A3").End(xlDown).Row - 2, 1).Value = "=SUM(A3+1)"
The example assumes there are no blank rows in column 'A', it just adds 1 to the value in column 'A', you can change that for the formula you need.

Note: The resize section is getting the last used row in column 'A' and taking 2 away (as you are starting in row 3). It is then seeing how many columns you need, in this instance just 1.
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,779
Office Version
  1. 2010
Platform
  1. Windows
Here's one way:

Code:
Range("D3").AutoFill _
    Destination:=Range("D3", Cells(Cells(Rows.Count, "A").End(xlUp).Row, "D"))
 

NataliaMSN

New Member
Joined
Mar 16, 2011
Messages
5
Ok I think I understand what you are saying and it works for the problem I mentioned but I guess I am not understanding what Row part of the equation because I am trying to use this formula again in the column "P" and I wanted to use Column "J" as a Reference like I did previously and my formula is:
=IF(AND(M3="Y",I3="H"),1,0) for some reason I'm not getting it right
 

sage_bob

New Member
Joined
Apr 27, 2005
Messages
28

ADVERTISEMENT

Okay...

The following starts at the range 'P3' and extends the range to match the number of rows in column 'J'. If there is data in cells 'J3' through to 'J50' then it extends the range to be 'P3:P50'

It then puts the formula into all of the cells. Example below.
Code:
Range("P3").Resize(Range("J3").End(xlDown).Row - 2, 1).Value = "=IF(AND(M3="Y",I3="H"),1,0)"

Hope that makes some sense ?
 

NataliaMSN

New Member
Joined
Mar 16, 2011
Messages
5
Nevermind sorry I was in the process of posting when that other post was placed.
Thank you my friend from the great state of Texas that works.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,331
Messages
5,595,549
Members
413,996
Latest member
mabelO

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
Top