Dynamic VB Code For Autofill

Jun 22, 2014

It has been a while since I worked with VB and I am struggling with some simple code.

I have an Excel sheet that I am using to track client information on, the client name starts on A3 and the list of clients we are tracking will vary from week to week.

I have values in B3:D3 that I need to auto fill based on the values that I have in column A. For example, if column A goes to row 33 then I want to auto fill B3:D3 down to row 33.

The code that I have now works as band aid, but I need something more dynamic.

I have found some solutions on line but none of them worked on varying lengths, the following is the code that has worked so far.

Sub Autofill()
'
' Autofill Macro
'
Range("B3:D3").Select
Selection.Autofill Destination:=Range("B3:D36")
Range("B3:D36").Select
Range("B3").Select
End Sub

View 3 Replies


ADVERTISEMENT

Autofill Dynamic Row Ranges

Feb 21, 2007

I've got a spreadsheet that I download a list of information into. The information relates to activities that are taking place e.g. start time, end time, type of activity (e.g. meeting) and duration (which identifies the length of the activity in 30 min slots e.g. 9.30am - 11.30am = 4).

The rest of the columns are labelled to represent the time in 30 min slots starting from 9am. What I would like excel to be able to do is to identify the first cell in the range which would be the cell that represents the start time in the row. Then from this cell fill cells in the row up to the end time with something - it doesn't matter what as long as the cell can be differentiated from the other blank cells in the row.

I don't think that I've explained myself that well so I've attached the spreadsheet for you to look at.

View 4 Replies View Related

Autofill Dynamic Columns And Rows

Nov 30, 2009

I have searched for this on the site as I thought it would have already been asked but I couldn't find anything. I have a formula in cell C7 which I wish to copy both down to the last row (xlup from column A) and across to the last column (xltoleft on row 6) but I cant seem to work out how to do it. I have used the .autofill before but for dynamic rows only. Is it possible to do for columns too?

View 2 Replies View Related

Autofill Cell Based On Results Of Multiple Dynamic Dropdown Lists?

Aug 25, 2014

how best to do this (bare with me I'm not quite a pro at excel yet!). I'll attach my doc (JMP Excel Forum) so you know what I'm taking about. I've set up the data to work in a similar way to this, as you can see I've a table set up (Appliance Sheet) which feeds information to the Main Sheet which contains the drop down lists.

What I need it to do is autofill the wattage column (Main!F8 onwards) with the wattage for the device as described in Appliance!N3 or N4 for example. For the wattage column to equal 28 (equivalent to Appliance!N3) then the following would show in the dropdown selections Type>Computers SubCategory>Monitors Device>BENQ G2222HDL Status>On

Is there a way to do this with the set up I have?

I did have a previous version of the whole worksheet that each Device had its own table and I looked up the wattage using and If formula to lookup a info on the device and knowing where to look it up based on the subcategory

=IF(ISERROR(VLOOKUP(D7,IF('Main UI'!C7="Heating_Cooling",Appliances!$A$7:$B$14, IF('Main UI'!C7="Kitchen_Bathroom",Appliances!$A$16:$B$27,IF('Main UI'!C7="Monitors",Appliances!$A$52:$B$62,IF(C7="Computers",Appliances!$A$64:$B$68,........

And I got it to work but it was getting to cumbersome to add in new devices and update the formulas. If attached that doc (OLD) so you know what I'm talking about. The last two sheets are the same sheets that make up the new document (JMP Excel Forum)OLD.xlsm

I really prefer the new way I've got it set up. Its easier to add new information or options to the dropdown list

View 2 Replies View Related

Autofill Code

Oct 30, 2008

I have this bit of code;

Selection.AutoFill Destination:=Range("j2:j20000")

But I want it to only autofill as far as the data goes in column I rather than down to row 20000

View 9 Replies View Related

AutoFill Formula Code

Jan 4, 2008

I am trying to use autofill over a range of cells.

I am using a Do While loop to find an empty column in row 6 incremented by 5 based on LFound. The starting value of LColumn is 9 and is increased based on and IsEmpty condition.

Do While LFound = False
LColumn = 9
If IsEmpty(Cells(6, LColumn).Value) = True Then
LFound = True
Else
LColumn = LColumn + 5
End If
Loop

Next I want use this column index to put an equation in a cell

Cells(15, LColumn).Formula = "='" & SheetName & "'!C103"

Last I want to autofill the 8 cells below the refrenced cell.

Cells(15, LColumn).Select
Selection.AutoFill Destination:=Range(Cells(15, LColumn) & ":" & Cells(23, LColumn)),
Type:=xlFillValues

But I can't get the autofill to work. I think it is because of my attempt at going from Cells() to Range(),

View 3 Replies View Related

AutoFill Code With Variable As Row Number

Aug 7, 2007

Just a niggling problem, I've got lstRow as a Long and it contains the value of the last row offset by (1, 0). The problem is i'm trying to add it into a range

Range("C500:K500").Select
Selection.autofill Destination:=Range(C" & lstRow &":K" & lstRow &")Type:=xlFillDefault

Like that.. Except i've tried a million different combinations of " and & in different places to try and get it to compile. It refuses too. It always gives the error "Expected list seperator or )" I know I could just do it individually from C to K but I'd like to learn how to do it this way as well.

View 6 Replies View Related

Lookup Code Prefix From Another Page And Autofill With Alphanumeric Sequence

Mar 24, 2014

I'm looking to populate a series of sequential codes based on a code prefix.

Sheet 1: Master Code list
Column A = Lookup Value
Column B = Code Prefix

Sheet 2 - Results page
Column A - list of lookup values - sorted in value order - The number of occurances varies for each value
Column B - Results list

I want to populate Column B in the second sheet with a sequential code list for each different value in column A. So for the first value it would have the prefix then proceed numerically (Prefix0001, Prefix0002, Prefix0003...) then for the next value its prefix in sequence (2ndPrefix0001, 2ndPrefix0002, 2ndPrefix003...), etc

I'm wondering if there is a way to do this all in one step or else if there is a way way to number each occurance of the lookup value in the second page, in which case the code can be concatenated easily by a lookup of the code.

I suppose on the back of this there is another query - is there a way to concatenate a number where the format is 000# where the concatenated value will retain the leading zeros? I've been trying and it is stripping them out.

View 2 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

VBA Code To Reference Dynamic Cell Value

Dec 22, 2011

I am looking to start writing a code that will a row # from a dynamic cell within the workbook and use that row # to select the row and delete it.

Example:
In Cell G5=8

I would like the VBA code to see 8 as row 8 and delete row 8.

Row 8 is determined by looking up a name and finding which row it is in and returning the row number.

View 1 Replies View Related

Code To Find The Last Row In A Dynamic Page

Apr 27, 2007

I have a task that pulls out information from the website. I need to write a vba code to find the last row. Since the no of rows are always not the same. I would need the excel masters help to solve it. Just a small piece of guidance would also help me.

In my work sheet I need to find the word " Function Name: Cleaning" if this is there then I should find the occurence of the word " name". If I find that then the code should copy the values in the column after name till it sees a space ( means no value). Should copy till that and paste that in another work sheet.

View 9 Replies View Related

Code Dynamic File Path

Jun 14, 2007

I have a question. How to code the filepath name to make sure it change when i move my files from one directory to another. Example:

I need to update 4 files from this directory, but i am moving them to another directory.
FROM
c:documents and settingTesting
TO
The file being able to follow which ever folder.

View 6 Replies View Related

Add Dynamic Named Range Via Code

Nov 30, 2007

I am using follwoing piece of code for offset function. For Some reason it is not working.

Reference = Cells(TableRowNumber, TableColumnNumber).Address
Col = Application.WorksheetFunction. CountA(rngF.Columns(TableRowNumber, TableColumnNumber).EntireColumn)

ActiveWorkbook.Names.Add Name:=TableName, RefersToR1C1:= _
"=OFFSET(Reference,0,0,Col-3,1)"

Col value is also being calculated to zero. TableRowNumber and TableColumnNumber are the variables which store the starting location of the column.

View 2 Replies View Related

Dynamic Assignment Of Value To Variables Using Macros And VBA Code

Jul 6, 2012

I have two columns one with the variables names and the other with the values now I have to assign vales to teh variables dynamically using the macros and vba code.

View 7 Replies View Related

Dynamic Userforms :: Code That Changes The Height Of A Userform

May 16, 2008

I am looking for some code that dynamically (during processing) changes the height of a userform. What I am trying to do is this: I have ten worksheets but only five are being used. I am looking to have a userform with a checkbox for each of the active sheets labeled. I don't want to have to display a form that is basically ten checkboxes with five enabled and five disabled. I want to show only the five active sheets checkboxes with a userform only large enough for the five. If six are active then a userform displaying six checkboxes and a userform large enough for only the six to be displayed.

View 9 Replies View Related

Create Dynamic Named Ranges With Code

Oct 13, 2007

I am employing code to label dynamic ranges that takes the form of,

ActiveWorkbook.Names.Add Name:="dms", RefersToR1C1:="=OFFSET(DMS!R10C5,0,0, COUNTA(DMS!C5),COUNTA(DMS!R10))"
'dms_j
ActiveWorkbook.Names.Add Name:="dms_j", RefersToR1C1:="=OFFSET(DMS!R11C10,0,0,MATCH("" * "",DMS!C10,-1),1)"
'dms_p
ActiveWorkbook.Names.Add Name:="dms_p", RefersToR1C1:="=OFFSET(DMS!R11C16,0,0,MATCH("" * "",DMS!C16,-1),1)"
'dms_r
ActiveWorkbook.Names.Add Name:="dms_r", RefersToR1C1:="=OFFSET(DMS!R11C18,0,0,MATCH("" * "",DMS!C18,-1),1)"
'dms_t
ActiveWorkbook.Names.Add Name:="dms_t", RefersToR1C1:="=OFFSET(DMS!R11C20,0,0,MATCH("" * "",DMS!C20,-1),1)"

The dynamic ranges are getting entered but the problem is that the range "dms" overshoots by six cells into blank cells at the bottom of the table, and the rest of the ranges overshoot by ten cells into blank cell area. I have deleted, cleared and destroyed everything around the table and re-sized the active area to no avail.

View 9 Replies View Related

Define Dynamic Range In Macro Code

Feb 26, 2008

I have been tring to define a dynamice range in VBA. At the moment, I use following method to Define the range,

Sub OTC_Future_Total()


Dim DynamicRange As Range

Worksheets("FinalReport").Select
Range("e9").Select
Set DynamicRange = Range(Selection, Selection.End(xlDown))
DynamicRange.Select...

View 5 Replies View Related

Excel 2010 :: Condensing VBA Code - Using Dynamic Variables?

Jul 17, 2012

I have some VBA that dumps various sheets data into an SQL Database.

Part of that requires me to sanitize all of the fields before they make it to the DB, (at least to prevent the code from breaking itself w/ errant ' characters.

right now my code is as follows

Code:
If InStr(aa, "'") > 0 Then
aa = Replace(aa, "'", "''")
End If
If InStr(bb, "'") > 0 Then
bb = Replace(bb, "'", "''")

[Code] ......

I was hoping to condense it to something like the following, however it is not working how I hoped / want it to. .. I had found somewhere out there that this Eval() function possibly could be used to 'reference' dynamic variables, however it does not appear to work at all anymore, and even then it may only have worked to 'read' and not 'write' to the variable. (Excel 2010, on Windows 7 64-bit).

Code:
itemsToSanitize = "aa,bb,cc,dd,ee,ff,gg,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz,aaa,bbb,ccc,ddd,eee,fff,ggg,hhh"
ITSArray = Split(itemsToSanitize, ",")

For Each thing In ITSArray
If InStr(Eval(thing), "'") > 0 Then
Eval(thing) = Replace(Eval(thing), "'", "''")
End If
Next thing

View 7 Replies View Related

Set Pivot Table Dynamic Source Range Macro Code

Apr 9, 2008

Ultimate goal is to automatically update the source data for 4 pivot tables that are on 1 worksheet. The data for those 4 pivot tables are on 4 different worksheets w/in the same workbook. Consolidating into one dataset is not an option.

I'm familiar with a dynamic named range, but the 4 worksheets that contain the data are replaced daily via automated Access output which creates an error.

I know how to do this adhoc by matching the pivot table names with their respective worksheets, but there are many other documents with similar layouts where this would beneficial.

Below is an example of how I currently update 3 pivots on separate worksheets w/ the same data range which is w/in the same workbook. My proposed changes are below the current. Any ideas on how to return the workbook name as a string...Or am I going about this the completely wrong way...

View 8 Replies View Related

Macro Code Create Pivot Table Based On Dynamic Source Data

Nov 28, 2006

The "Sum" sheet can change its number of rows. The pivot table is based on it. I'm having trouble with the SourceData portion of the code in my macro ....

View 9 Replies View Related

How To Name A Dynamic Range & Make A Validation List (of 2 Dynamic Ranges)

Dec 22, 2009

I have a range which will change in size & in content, & I want this to be a Named Range at whatever size it is.

Reason I want to is because I want to make a Validation List with this dynamic range. I also want a Validation list which lists the content of 2 or more dynamic ranges which may or may not be on the same worksheet - is this possible?

i.e.
First dynamic range: called "Milestones" at A11
Second dynamic range: called "Activities" at A25
& make a Validation list that will list content of both

View 9 Replies View Related

Dynamic Starting Point For Dynamic Named Ranges

Jun 21, 2009

I would like to replace the blue bit of this Dynamic Named Range (DNR) with an INDIRECT formula in order to modify the starting point for the DNR: =OFFSET(DATA!$C$60,0,0,20,1). Unfortunately, I can’t seem to get my INDIRECT formula to work in order to use it to replace the blue bit above: INDIRECT("'"DATA"'!&ADDRESS(MATCH('SHEET1'!AC8,DATA_Date,0)+22,3)"). The orange bit of the formula above returns a value of 60, therefore the ADDRESS formula should return $C$60, that can then feed into the INDIRECT and act as the equivalent of DATA!$C$60. But it doesn’t.

View 2 Replies View Related

Dynamic Data Validation :: Dynamic Lists

Jun 24, 2009

I have a question on the above but can't seem to find a solution. There are two ways that I can find for dealing with dynamic lists via data validation:-

1) Offset and match, cavet being the data must be sorted a-z
2) Have lists for each potential selection

Is there any way to get around 1 without having to do 2? E.g. Got two columns of data, unsorted, and a list from which the user can choose from. The user chooses from the list in first cell, in the second cell require the dynamic list to return all the values accordingly?

View 5 Replies View Related

How To Create Dynamic List Within Dynamic Table

Oct 31, 2013

I have a dynamic table which is linked to a couple of charts. The table must remain dynamic.

I needed to add two new columns to the table, "Focus Area" and "Category". I need a drop down list in the "Category" column to be dependent on the item selected from a drop down menu in "Focus Area".

I can get the first row of the dynamic table to do this.... however; subsequent rows all lock the drop down list in the "Category" column to the same choices regardless of what is chosen in the "Focus Area" list.

Is there a way to make dynamic drop downs within a dynamic table?

View 1 Replies View Related

Autofill With Max Value Specified

Nov 3, 2009

I am trying to simplify my data entry and I have this idea that I do not know how to tackle, but it would be nice to have it worked out.
I am looking for an autofill macro that will fill column B2 to Bxx with values from 1 to max value specified in cell B1. Lets say I know I have 5 trees I need to enter. I want to enter "5" in a cell as a reference, and everything else will be filled in automatically with press of the button.

To make things even more productive I would like to use value from cell A2 and replicate it through the range specified above in column A2:Axx.

Result: ....

View 6 Replies View Related

Autofill Value Down

Mar 13, 2009

I have this ActiveCell.Offset(0, -1).Range("A1").Select. Selection.AutoFill Destination:=ActiveCell.Range("A1:A6"). However I need to copy the value down, so it is identical to the Range("A1"). At the moment it adds one year to each value when copied down. e.g. A1 = 12.01.09. and it copies it down so I get 12.01.10, 12.01.11 etc... I want them all to be 12.01.09

View 3 Replies View Related

Autofill To End With VB

Nov 13, 2009

I am looking for a way for my macro to select cells C4:T4 and then auto fill the formulas down to the last row with data. I have found suggestions when working with one cell to auto fill, but cant seem to find a way to do it with a range of cells

View 2 Replies View Related

AutoFill SET To The Last Row

Dec 29, 2009

I have a Macro and I need to code it to Autofill a formula in column B with data from A and I need to set it to AutoFill to the last row. Probably basic but I've tried a couple posts previously and I am just not getting it. This is what I currently have. Sorry, I recorded it and have some additional steps in here I don't need.

View 6 Replies View Related

AutoFill To Last Row?

Apr 23, 2009

I have a piece of code that includes the following line:

Selection.AutoFill Destination:=Range("B1:B9414")

I want it to always autofill to the last row that has content in it. I have been changing the value to a large number that I know is always more than the content of the worksheet which changes periodically, but I would rather it always only go to the last row that is not empty so I don't have to go back and delete those extra rows.

View 9 Replies View Related

Autofill Using VBA

Dec 27, 2008

I have a spreadsheet with data where the number of rows change daily, in column D.
I have formula in column E which I autofill manually by double clicking on the cross thingy of the first cell.
However I'm trying to do it using VBA, but it always stops at a certain row and not where the column D data stops.

Below is the macro which stops autofilling at row E7762

Selection.AutoFill Destination:=Range("E3:E7762")

Is there a way to amend the VBA to autofill based where Column D data stops?

View 9 Replies View Related







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