Autofill Range Using VBA Based On 2 Variables

Jan 14, 2014

I am trying to write some code that keeps throwing me the error message "Autofill method of range class failed". But I cant understand why, I think it may have something to with my range notation:

Code:
Sub SummariseSheets()
'collates individual client development data from consultant
'worksheets and compiles in one sheet on summary page

[Code]....

The error is in the "Selection.AutoFill Destination:=("C" & LR & ":C" & LR2), Type:=xlFillDefault" line, however I cant figure out why? The code essentially takes a section of data from multiple worksheets, then pastes it onto the summary page. It then adds the name of the sheet the data has come from into column C next to the relevant rows.

View 2 Replies


ADVERTISEMENT

Autofill With Variables ...

Oct 15, 2007

I am having major trooble getting Autofill to do what I want it to - I have looked at pretty much every result on a search here, and as far as I can see, I can't find any problem with my code -

If FormShiftSet.BoxS.Value = True Then
SourceRange = "C" & x + 1
Range(SourceRange).Value = "S"
fillRange = "C" & x + 1 & ":" & "AX" & x + 1
Range(SourceRange).AutoFill Destination:=fillRange
End If

I want to do is fill the value "S" in all cells from "c" & x+1 to "ax" & x+1" - at the moment the code fills the first cell (SourceRange) with "S", but it gives the 'AutoFill method of Range class failed' error once it gets to the right point -although the variables are correctly referrenced after the error.

View 4 Replies View Related

Autofill With Variables

Jan 9, 2008

I'm having a bit of a problem with syntax.

Sub Macro2()
Dim rng As Range
Dim rng_AutoFill As Range
Set rng = Range("A1:E1")
Set rng_AutoFill = rng. CurrentRegion
rng.AutoFill Destination:=Range(rng_AutoFill)
'rng.AutoFill Destination:=Range("A1:E36")
End Sub

If I replace rng.AutoFill Destination:=Range(rng_AutoFill) with the commented out version rng.AutoFill Destination:=Range("A1:E36") it works fine. I can select the rng_AutoFill range, I don't seem to be able to use it with a variable name.

View 6 Replies View Related

Sum Of A Range Based On Two Variables

Jun 18, 2009

I'm trying to create a simple checkbook application for a friend. I've gotten pretty much everything I want figured out except for two functions, which are basically the same thing. I'm trying to find the sum of all deposits and of all withdrawals based on two entered dates.

Basically, they enter the dates, and the formula finds the dates, then sums all the deposits/withdrawals between them. I attached the workbook with some sample data in case I wasn't really clear.

View 2 Replies View Related

VBA Select Range To Copy Based On Two Variables

Jan 13, 2014

I have a Macro that already works great but now I need to look for another variable to sort it down even further. I think it can be done by setting up a "Case" but still not sure how to do that. It already looks through the range to find all the rows that return a value of "True". Now I need it sort those results so it only returns what has a specified value in Column "AJ". I am looking to do several choices (Listed Here). So the end result will be all the items that return "TRUE" In Column "AI" and are Items that return one of these values per Case "Starters, Appetizers, Soup, Salad, Entree, Dessert, Special" with then copy over in the exact format that is listed in the code below.

For example All the items that are selected with "TRUE" can be narrowed down to all of those that are "Salad" as well - Then copied over in the exact format that is listed in the code below.

What I am doing is breaking out all the different course of food and putting a Header in-between each (That is already built and working) - So I can select all the food from a master list and then put it in order on the "Catering BEO" Sheet with Headers in between

Code:
Sub BEOA4()
Application.ScreenUpdating = False
Dim wsSource As Worksheet
Dim wsDest As Worksheet
Dim FoundX As Range
Dim FirstFound As String
Dim lastrow As Long

[code]....

View 3 Replies View Related

Merge Cells: Select A Range Based On Two Variables Which Store The Column Numbers

Jul 19, 2009

I am trying to select a range based on two variables which store the column numbers. what I have is:

View 4 Replies View Related

Macro To Change Range / Action Depending On Worksheet (range To Autofill)

Sep 17, 2013

Currently my Macro should: Turn off any filtersNumber column A from 1 to 1000 (starting in A14)Drags formula from K14-O14 down to last row of data shown in column Athen puts cursor in last empty cell in column B ready for user to enter data

On point 3 - I want the range to be K14-O14 if active worksheet equals "EXCHANGES" but if its on the "VALUATIONS" tab the autofill range should be L14-P14

I have found bits and pieces of macros on the internet and put them together so if my macro below is not the most effective for my needs but here it is in it's current state:

Here is my macro:

Sub AddNewEntry()
'TURNS OFF FILTER IF FINDS ONE ON
Dim wks As Worksheet

[Code]....

View 8 Replies View Related

Autofill In Macro Range Is Constant How Can I Code To Be A Variable Range?

Feb 19, 2010

I am trying to write a macro which will autofill specific columns. The macro will set the range from the start of my autofill to the end of my autofill as a constant range.

The problem I need to get around is the end of my range can always change each time I run the macro. For instance, the first time I run the macro I may only need to autofill from row 4 to row 15. The next time, I may only need to autofill from row 4 to 23 (because of user updates). How can I make the end of my range not be a constant address but variable?

View 6 Replies View Related

Autofill To Last Row In Range

Sep 27, 2013

I have multiple worksheets each with varying amounts of data. I have a number in cell A1 that I need to autofill down to the bottom of each worksheet. All of which have varying amounts of data.

RA-0151
0
765804
3308345
168
0
5.74E-07
8.8E-09
1.371696
0
0

[Code] ........

When I record a macro it sets the autofill range as the bottom of what ever worksheet I recorded it on.

How can you write a macro that goes to the last row of each worksheet.

Sub Macro1()
'
' Macro1 Macro
'
' Keyboard Shortcut: Ctrl+a
'
Range("A1").Select
Selection.AutoFill Destination:=Range("A1:A122"), Type:=xlFillCopy
Range("A1:A122").Select
Range("B1").Select
End Sub

View 2 Replies View Related

AutoFill Based On Variable Last Row

Jan 20, 2008

What I need to be able to achieve is a function in my macro that will

a: Count the number of rows in the active sheet
b: Allow me to use this info in other functions, such as subtotals, autofills

After searching many sites I'm pretty certain the function I need to use is "rowcount".

I've managed to incorporate a loop using this function, which is fine when running the macro but not so good when you are stepping through 5000+ rows

RowCount = ActiveSheet.UsedRange.Rows.Count
For x = 2 To RowCount
Cells(x, 42).Select
ActiveSheet.Paste
Next x

So for me now it seems as though "x" should represent the number of row that has been counted in the above code. But when I try to use "x" in functions the macro falls over

Range("AQ2:AX2").Select
Selection.AutoFill Destination:=Range("R2C43:RxC50")

View 3 Replies View Related

Autofill Range From Another Worksheet?

Mar 24, 2014

I am trying to autofill cells across a column that sum a range but move over 5 columns from another worksheet. for example, i want to take this range:

Schedule!AG6:AK6 and when I autofill, the next adjacent column will fill with Schedule!AL6:AP6, the next with Schedule!AQ6:AU6, and so on.

I have tried offset, but am not sure if that's the right formula.

View 5 Replies View Related

Autofill Using A Selected Range

Jan 4, 2008

I am using the following code to Autofill a formula through a variable range:

Selection.AutoFill Destination:=Range(MyFormulaCell, TerminalCell), Type:=xlFillDefault

MyFormulaCell is the cell with the formula, and TermnialCell is a variable set on a count of rows. This is working great, and I can loop through this for the columns I need to copy just fine by incrementing values, but as I apply this to several sections, it's taking me up to a minute to run the macro. In this "I want it now" day and age, I'm sure my coworkers for whom I am making this will not be happy to wait that long.

Is there a way that I can incorporate a selected range into this method?

I'd like to set MyFormulaCell to:
Range(Selection, Selection.End(xlToRight)).Select
and then autofill the formula down the number of rows contained in TerminalCell.

View 9 Replies View Related

AutoFill With Variable Range

Nov 1, 2006

I have worksheets that refernce values in one column off columns in others and do this on daily basis. each day there are blank amounts in random fields which I inturn use a macro to delete rows with blank amounts

I then want to autofill the numbers from 0001 to the bottem line of the sheet where the word "END" always is, as the position of the end word is random each time and autofill always needs a definite range how do I get my macro to autofill down to the word "end" ?

here is the code that doesnt work for me and I've been trying to fix

Sub Macro1()
For counter = 1 To 30
Set curCell = Worksheets("Sheet1").Cells(counter, 6)
If curCell.Text = "END" Then Range(Cells(1, 6), Cells(counter-1, 6)). _
Selection.DataSeries Rowcol:=xlColumns, Type:=xlAutoFill, Date:=xlDay, _
Trend:=False
Next counter
End Sub

View 3 Replies View Related

Use Variable For AutoFill Range

Oct 12, 2007

I am creating a loop that will autofill 16 cells down. It copies the formula from one cell (Z230), pastes that 16 cells down (cell Z246), then changes the lock properties of the cell (Z246) before autofilling down 16 (to cell Z261). At which point the loop starts over again. (copies cell Z246,pastes it to Z262, fills down 16 , etc)

Because the cell I am copying from changes in each loop, I set a variable to grab the address of the starting cell and last cell of the copy.

I then put this into a String so it would return something like this

Range("Z245:Z259")

Problem is I get extra quotes around Range("Z245:Z259") - it comes out as string "Range("Z245:Z259")"
This gives me a problem when I try to replace

Selection.AutoFill Destination:=Range("Z245:Z246"), Type:=xlFillDefault

with


Selection.AutoFill Destination:=rangevariable, Type:=xlFillDefault

Below is my total code, but I get stuck on the selection line. I have to do this 300 times so I would prefer not to do it manually!

View 9 Replies View Related

Copy Range & AutoFill To Last Row

Jan 26, 2008

I have 2 sheets - 1st sheet holds the data that is updated periodically. 2nd sheet pulls the data into A2:k2 and formats it for importing to another program. I need a macro that will copy the data from A2:K2 and auto fill down all rows from sheet 1 that contain data. I have read previous threads for autofill with no success using my below code.

Sub FillDownToLastUsedCell()
Sheet 'RawDataA2:K2' Range("A2:K2", Cells(Rows.Count, "Sheet 'RawData'A2:K2").End(xlUp)).FillDown
End Sub

View 6 Replies View Related

Autofill Based On Cell Condition

May 20, 2014

I have a workbook sheet change condition that, when triggered runs the following code (amongst others).

[Code] ......

What I would like is to amend the above (possibly in a loop?) so that it skips the rows in which the value "New" features in range F17:F190.

So basically Autofill as per the code but leave the values in the cells of the range in which New features in range F17:F190

View 4 Replies View Related

Autofill Last Day Of Month Based On Another Cell

Jul 25, 2012

In cell A12 the format is mm-###. Based on the mm (2 digit month) in cell A12, I would like cell B12 to auto fill the last date of the month as mm/dd/yyyy.

View 4 Replies View Related

Autofill Rows Based On Number

Jul 26, 2012

I have wookbook with a lot of sheets on it

The first sheet to be filled is called "Local Info"

In this sheet in the Active Cell "G7" the user must register a number between 0-500

This number must affect my next sheet called Competence Map Autofilling rows 7+8 from Columns A to AM

So If for example I put 83 in "local INFO" G7.

I will get 172 rows with text (the first 6 Headers) the 7-8 original and from 9-172 filled with the information given.

View 3 Replies View Related

Autofill: Vertical Range To Horozontal.

May 12, 2009

I would like to be able to use autofill from a vertical range to a horozontal one. In the example, if you click and drag on cell "R3" (=M3) it samples to cell dirrectly below it "M4", when I want it to sample the cell M6, M9 ect,ect. Is there a way to program the autofill to skip cells?

View 2 Replies View Related

Autofill For Unknown Range In Different Sheet.

Jun 16, 2009

I need to autofill a range of formulas (A2:O2) but the actual range to fill up depends on the range of data on sheet1. I've managed to use:

View 4 Replies View Related

Autofill Not Detecting Range Pattern?

Apr 10, 2013

I have the following series of formulas consecutively in a single column:

=IF(A3=INDIRECT(ADDRESS(2+MATCH(MIN(H3:H50),H3:H50,0),1)),"YES","NO")
=IF(A4=INDIRECT(ADDRESS(2+MATCH(MIN(H3:H50),H3:H50,0),1)),"YES","NO")
.
.
.
=IF(A50=INDIRECT(ADDRESS(2+MATCH(MIN(H3:H50),H3:H50,0),1)),"YES","NO")
=IF(A51=INDIRECT(ADDRESS(2+MATCH(MIN(H51:H98),H51:H98,0),1)),"YES","NO")
=IF(A52=INDIRECT(ADDRESS(2+MATCH(MIN(H51:H98),H51:H98,0),1)),"YES","NO")
.
.
.

Effectively, I am comparing the values in each set of 47 to determine which one is the smallest. The smallest entry will get a YES label next to it and all others will get a NO. The problem I am having is the the autofill feature is not correctly detecting the pattern, even if I manually fill in the first 49 entries (shown above). If I hilight all of the above entries and autofill one down, I get the following:

=IF(A53=INDIRECT(ADDRESS(2+MATCH(MIN(H53:H100),H53:H100,0),1)),"YES","NO")

It should be:

=IF(A53=INDIRECT(ADDRESS(2+MATCH(MIN(H51:H98),H51:H98,0),1)),"YES","NO")

Basically I need the H:H: reference to stay constant, but only for 47 cells at a time. After that, both the lower and upper bound should increase by 47. Is there any way to indicate this to Excel? Manually typing in the new formula every 47 entries isn't practical because the spreadsheet has thousands of entries. How I can accomplish this using a single formula and autofill?

View 2 Replies View Related

Absolute Range - AutoFill Via Macro

Jul 1, 2009

In a macro - how can you copy a cell and keep a data range absolute?

In the statement below, the range denoted by: DATA!RC[-52]:R[829]C[-52] is D2:D829. When I use the macro to Autofill using the following:

(Selection.AutoFill Destination:=Range("BG2:BG220"), Type:=xlFillDefault)

the range progresses. I need to have the range as an absolute.

Sheets("Report").Select
Range("BG2").Select
Selection.FormulaArray = _
"=SUM((DATA!RC[-52]:R[829]C[-52]=""APPOINTMENT"")*(DATA!RC[-55]:R[829]C[-55]>=Report!RC[-1])*(DATA!RC[-55]:R[829]C[-55]

View 9 Replies View Related

AutoFill Cells Based On Combobox Selection

Jul 14, 2014

What I'd like to do is fill specific cells with specific information drawn from other pages based on a combo box selection.

For example, if I were to pick 10131 in the combo box, I'd like it to fill out cells X, Y and Z with information from the three cells to the right of 10131. Assume X, Y and Z are not touching.

View 1 Replies View Related

How Do I Autofill Colors, Based On Input Of Text

Jun 16, 2008

i'm trying to do is have a formula that when certain text is typed into column 'b' (fmc, nmcmc, etc... anyways..) when an airplane is 'fmc' its 'green' and i want the aircrafts tail number block in column 'a' to autofill in with a green color, and when its 'nmcmc, i want it to be red. when its 'bq' i want it to autofill in as yellow.

View 10 Replies View Related

VBA Autofill Based On Specific Cell Values?

Aug 25, 2012

I want a range to be filled based on 2 cell values in my sheet. The autofill range should be filled based on the values in the input range. For instance in cell A1 I place the value 1 and in cell A2 I place the value 10, then the macro should automatically fill in the numbers from 1 to 10 in another column. If I change for instance the input values to 5 and 15, then the autofill range should fill up the numbers from 5 to 15.

View 4 Replies View Related

AutoFill Column To New Sheet Based On Value - Autoupdate

Mar 31, 2014

Master Template
Project 1
Project 2

Task 1
1 - Mar
28 - Dec

Task 2
2 - Mar
2 - Jan

Project Due
5 - Mar
4 - Jan

Above is a table we have for high level tracking on specific tasks due for projects.

What I want to do is: If the last cell in a column = Jan then it will automatically copy the whole column and insert it into a Sheet named January and have it automatically update. Below is the end result.

January Template
Project 2

Task 1
28 - Dec

Task 2
2 - Jan

Project Due
4 - Jan

View 7 Replies View Related

AutoFill Formula Based On Data In Another Sheet

Jan 20, 2008

Here is my test example I am trying to figure this out with.

Sub a()
Dim rg As Range
'set formulas to be filled
Range("A1").Select
ActiveCell.FormulaR1C1 = _
"=IF('sheet2'!RC="""","""",'sheet2'!RC)"
Selection.AutoFill Destination:=Range("A1:L1"), Type:=xlFillDefault
'now get autofill to populate until no more data on sheet 2
Set rg = [a2]
Set rg = Range(rg, Cells(Rows.Count, rg.Column).End(xlUp))
rg.Cells(2, 2).AutoFill Destination:=rg, Type:=xlFillDefault
End Sub

Without VBA, once I set the formulas for A1:L1, I can use the mouse to autofill all columns until Im around row 27,000.

Id like to be able to run a check for the end of data in sheet 2 so that if the sheet2 changes, it will all be included.

The resulting sheet1 cannot have any null values, so a perfect end of data check is necessary.

View 9 Replies View Related

AutoFill Down Rows Based On Another Columns Last Cell

May 13, 2008

I have a workbook which has one sheet "Raw Data" where I will cut and past blocks of data of various numbers of rows. Another sheet "level one calcs" conducts various calculations on the raw data. I was wondering if there would be any way to create a macro which would copy down (autofill) the last row of my my calculation page for the exact number of rows I added into the raw data. The goal here would be so that I dont have to highlight and copy down the formulas on the calc sheet each time I add in new data.

View 3 Replies View Related

Autofill Range While Leaving The Cell Number Same?

Jul 30, 2012

How can I auto fill a range while leaving the cell number the same?

Code: =IF(AND(B4>=c2,b4=c2,b4=c2,b5=c2,b6=c2,b7=D2,b4=E2,b4=F2,b4=G2,b4=H2,b4

View 7 Replies View Related

Excel 2010 :: Autofill Ever Changing Range?

Jan 23, 2013

Excel 2010

I have this code in a macro, the range will change as more data is added. so that I dont have to keep changing the range. How can I have this code autofill from the activecell to the last cell that has data in column M.

Selection.AutoFill Destination:=ActiveCell.Range("A1:A50000")
ActiveCell.Range("A1:A50000").Select

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved