Insert A Variable Number Of Rows And Copy And Paste From And To Variable Positions

Aug 8, 2009

On the attached Excel file, I have code that will insert a variable number of rows and copy and paste from and to variable positions. That all works fine when run from a command button, but when I try to run it from the Worksheet_Calculate by entering 1 in J1 or K1 (inrange cell is J1+K1 for testing purposes) the CommandButton1_Click sub runs continously until an error occurs.

View 4 Replies


ADVERTISEMENT

Copy And Paste Macro - Variable Number Of Rows

Jan 13, 2009

I am working on a macro where I am creating a formula to string together some text columns and then copy the formula down the entire column. The data source I will be performing this on will change in number of rows period to period. The data would be in columns A,B & C and the formula is in D. The formula in D is stringing together the data in AB & C and then I want to copy and paste that formula down to the bottom of all of the data. What would the code be for the copy and paste with variable rows?

View 9 Replies View Related

Inserting Rows In Variable Positions?

Nov 23, 2012

I'm analysing some data sets with variable content, and need to insert blank rows every so often to provide space to do some analysis. The problem I have is that the position of the blank rows change according to the data set, I have been able to calculate how often the row needs to be inserted using VBA as part of my import routine and saved this value to a cell, but I cant figure out how to write the VBA which will insert rows using this value and stop at the end of the data set.

In the attached example I need to insert a row each time the data in column 2 (name) changes, this is the value I have calculated which in this example is 7. So in this attached file I need to insert a row in row 2, row 9 and so on etc. But this is what changes depending upon the "Product" held in colum 1.

View 1 Replies View Related

Copy And Insert Rows From List To Ws Based On A Variable No

Dec 20, 2006

I have a bit of a curly one - I have a sheet with 9,000 records that I need to expand to 24,000 + on a separate sheet records using the following method:

1) Select and Copy entire row 2 from sheet(1)
2) Insert a number of new rows into sheet(2), based on the value of cells(2,8) or cell H2. Column H contains quantity values for each of the 9000 rows which are variable.
3) Repeat for row 3, copying and inserting into sheet(2) based on the value of the cell in H3.
4) loop through all records until complete

I have tried writing the code in VBA but am not even getting close!

View 9 Replies View Related

Copy / Paste With Variable Rows

Mar 16, 2012

I have some code that uses a form so you can choose the folder that contains all the spreadsheets that I need to copy. My issue is I have about 20 spreadsheets, some have the tab labled M3 and others Sheet1. Next is each spreadsheet has a different amount of rows in them. My data will always start in cells B4:N4 but may 20, 100, 1000 rows long.

My code works but only copies the first four rows of the last sheet open.

Code:

Private Sub cmdbtnProcess_Click()
Check_Path
End Sub
Sub Check_Path()
If txtboxPath.Value = Empty Or txtboxFile.Value = Empty Then

[Code]...

View 2 Replies View Related

Macro To Copy And Paste Into Another Sheet At Variable Rows?

Nov 14, 2012

Sheet 2 has 3 cells with values:

C14, C15, C16

I need VB code to:

copy the values in those cells

Return to Sheet 1, let the user click a cell in any row in Colum F, then Paste them (Special, Values and Transpose)

View 4 Replies View Related

Insert Formula Across Variable Number Of Columns With VBA

Jun 19, 2014

I have two variables - the number of stages, and the number of people.

The stages will start in say C22 through G22 (if there were 5 stages). The number of stages will vary upon a user-inputted number in A1.

The names of people will start inB29, so I'd like to insert the simple formula (=Max(C23:C28)) across cells C29-G29 (again with my example of 5 stages), with relative references to the columns, of course.

Ditto for the next name in B30, etc, so that I get the max value for Person#1 in Stage 1, 2, 3...Person#2 in Stage 1,2,3...

Inserting the formula over the dynamic ranges.

View 8 Replies View Related

Paste Formula In One Row To Variable Number Of Columns

May 9, 2014

get this macro to paste the formula across to a variable number of columns? It is falling over at

VB:
Range(Cells(5, .Columns.Count)).Paste
VB:
Sub Clear()
'
With ActiveSheet

[Code]....

View 4 Replies View Related

Paste Automation With Variable Columns And Rows?

Feb 25, 2013

I'm trying to come up with code that will allow me to take numbers arrayed as follows:

25
25
42
42

[Code]....

The number of rows and columns are both variable.

View 3 Replies View Related

Copy Paste With Macros - Variable Positioning

Jul 12, 2007

Using a macro, how do I tell Excel to:

1. Copy the xth row and paste it before the yth row

2. Copy the mth column and paste it before the nth column

3. Copy the cell a,b and paste it in he position c,d
where x,y,m,n,a,b,c,d are variables, the value of which the user inputs, say in cells A1, A2, A3, A4, A5, A6, A7 and A8 respectively.

In other words, I need to read numbers m and n which are the values of cells A1 and A2, then I need to go to column number m (for instance, if m=4, I go to column D), copy the whole row, go to column number n (for instance, if m=6, I go to column F), and insert the copied column.

Also wondering if VBA provides any way to quickly horizontally and vertially flip copied tables while pasting. While I am aware of the transpose function which swaps rows with columns, I am looking for a way to reverse the order of either the rows or the columns as per my need, without having to copy-paste row-by-row or column-by-column.

View 9 Replies View Related

Macro To Copy & Paste Variable Range

Aug 15, 2007

I am trying to write a very basic macro to copy and paste, but when I record the keystrokes, step 4 (see below) seems to be recording absolute cells and not relative (?). At any rate, I can't seem to figure out how to get it to select the text the way I want it to. These are the keystrokes I want:

1. Ctrl-c in the current cell <copy the current cell>

2. DownArrow <move down one cell>

3. Shift(hold)-End-Down <select the blank spaces from here down until the next occupied
cell>

4. Shift(hold)-Up <move the selection up one from the bottom to exclude the occupied cell>

5. Ctrl-v <paste>

6. End-Down <move down to the last occupied cell>

I have set the record tool to record "relative" references.

Below is the code that was recorded. It's line 5 that's not working - how do I fix it? What is the command to tell the program to press the shift key and an up arrow?? Such a simple thing, and yet I can't find the answer anywhere! Things sure have gotten complicated since the old Lotus 1-2-3 macro language...

Sub Fill()
Selection.Copy
ActiveCell.Offset(1, 0).Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveCell.Range("A1:A17").Select
ActiveSheet.Paste
Selection.End(xlDown).Select
End Sub

View 8 Replies View Related

Copy Variable Sized Row And Paste Select Columns Into Different Worksheet

Sep 29, 2012

I'm in the middle of building a code that will look at the value in Sheet: "DATA" column "J", for each row that matches a criteria that I pull from a cell - Sheet: "Test" Cell: "C1".

The number of rows varies. I want to paste columns: "I2, K2:P2, U2:AJ2" when the value in Sheet: "DATA" column "J" matches the cell "C1".
I'm using a Command button to click every time I want to generate the filtered data. And I would prefer the code to always copy data starting at Sheet: "Test" Cell: "K2".

I've copied, below, my test code that I have so far which only copies row 2 from the Sheet: "Data", and copies it into Sheet: "Test", starting at K2.

VB:

Private Sub CommandButton2_Click()
If Sheets("DATA").Range("J2").Value = Sheets("Test").Cells(1, 3) Then
Sheets("DATA").Range("I2,K2:P2,U2:AJ2").Copy
Sheets("Test").Cells(2, 11).PasteSpecial Paste:=xlValues, Operation:=xlNone
End If
End Sub

View 3 Replies View Related

Sum Of Variable Number Of Rows

Aug 7, 2009

I reckon this should be easier than I'm finding it, but I just can't seem to find the right combination of functions to solve this. In column A I will have an entry every 5 or 6 or 7 rows with blanks rows between. In Column B starting at every row corresponding with an entry in Column A there will be a short column of figures could be 1 2 3 or four or more of them. (the're will always be a blank between the last number in a group in B before the next entry in A). In column C starting at every Row corresponding to an entry in column A I want the sum of the group of figures in Column B.

But here's the rub.... The most important thing is that I can use the same formula all the way down column C. So click the one formula at the top and drag it all the way down 1000 rows.

View 4 Replies View Related

Variable Number Of Rows In Macro

Nov 2, 2011

I'm trying to write a macro with a variable number or rows depending on the total number of rows the workbook has.

I tried like this:

Code:
Sub provaanova()
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range(("$J$2:$J$") & Range("J" & Rows.Count).End(xlUp).Row) _
, ActiveSheet.Range(("$J$2:$J$") & Range("J" & Rows.Count).End(xlUp).Row), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

and:

Code:

Sub Provaregress()
r = ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$J$2:$J$r") _
, ActiveSheet.Range("$K$2:$M$r"), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

But it gives me an error. The only way i was able to do it without error was:

Code:
Sub Provaregress()
Application.Run "ATPVBAEN.XLAM!Regress", ActiveSheet.Range("$J$2:$J$53968") _
, ActiveSheet.Range("$K$2:$M$53968"), False, False, 99, "ANOVA", False, _
False, False, False, , False
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
End Sub

But as u can see it has a fixed number of rows. ( I need variable number of rows detected on column J, and then run regression with K,L,M as depending variables).

View 5 Replies View Related

Make A Variable Number Of Rows

Nov 7, 2008

I have made a very basic spredsheet which using an assumption table makes a particular column of values which works out the revenue. Then I just drag the box down to the number of rows I want it to go down.

However, I want to be able to enter a number in a CELL away from the tale eg. 50 and have the number of rows in the column go down to 50

View 9 Replies View Related

Select Rows With Variable Last Row Number

Aug 16, 2008

I'm trying to write a macro that will validate data in variable amount of rows but will always be in a specific column. what i'd like to do is count the amount of row entries in Column A to give me "iRows." Then validate data in column E from E1-E"iRows." Currently my data validation runs for the entire column which means i can not validate blank entries. Once I can limit the validation process from E1 to E "iRows" then I can consider blank fields and mark them as invalid.

Columns("E:E").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateDecimal, AlertStyle:=xlValidAlertStop, Operator _
:=xlGreater, Formula1:="1"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = "Award Amount"
.ErrorTitle = "Award Error"
.InputMessage = _
"Please enter the current expected total value or current award amount for this contract."
.ErrorMessage = _
"Award amount may not be set to 0.00. If you do not have an amount awarded simply make the award amount equal to the paid amount."
.ShowInput = True
.ShowError = True
End With

I've tried using different ways of counting the rows and have been able to define "iRows" the problem is defining the range to only column E from E1 to E"irows."

View 4 Replies View Related

Function To Sum Number Of Rows Based On Variable

Jun 23, 2014

As you can see in the attached excel doc, I have calculated a column for "Number of Claims Per week" and also "Dollar amount Per claim". This was done using VLOOKUP and distributions. That is not the issue.

The issue I am having is creating the "TOTAL" for the week. So for example, if week one generates 4 claims, I need to be able to add up claim amount #1-#4.

It seems as though this would be a basic function, but I can seem to find a way to add up a certain number of cells, based on a variable generated from a random number.

If you take a look a my excel sheet, I am trying to solve for the "Claim Total" column on the far right. This column should be the sum of (Number of claims * The individual amount per claim). Note that if there is 4 claims in that week, I would have to add up claim 1-4 to get that weeks total.

Question2.xlsx‎

View 9 Replies View Related

VBA - Copy Down Formula With Variable Rows

Apr 13, 2013

Here is my problem. I have a a workbook with 2 sheets.

Sheet 1= Data sheet; Sheet 2 = Table

On sheet 2 I want to copy down an entire row (A8:AH8) but the problem is that the number of copied rows depends on the number of rows contained in sheet 1 column A (-1 row)

So if i have 101 records (100 +label) in column A sheet 1, in my sheet 2, it must copy down the formulas from (A8:AH8) until (A107:AH107)

View 2 Replies View Related

Set Range Variable Using Variable Row Number

Mar 11, 2008

I am using a variable named " Totals" as a range type to refference the range in a formula. It works the way I have it.

Dim Totals As Range
Set Totals = [U37: AE37]

Now instead of the absolute refference, I would like to change the row refference by an offset of my current row, using a formula with a varriable. The columns stay the same.

View 3 Replies View Related

VB - Transpose Variable Number Of Columns Into Inserted Rows

Jul 23, 2012

I have a sheet with a company name in column A, and a list of comma separated values in column B. I can easily convert column B to multiple columns with the Text to Columns function, but then I'd like to insert each individual value in a new row in column B.

So, at the moment I have data that looks like this:

Company A
Value 1, Value 2, Value 3, Value 4, Value 5

Company B

Company C
Value 1, Value 2, Value 3

[Code].....

View 6 Replies View Related

Inserting Variable Number Of Rows And Populating Data

Jan 25, 2010

Inserting Variable Number Of Rows and Populating Data

View 10 Replies View Related

Copy Variable Number Of Columns Per Row If Data Exists?

Dec 4, 2012

My data looks like this in one sheet:

A
2
B
C

D
1
E

F
3
G
H
I

Where A is associated with 2 other letters, B and C. D is associated with one other letter, E, and F is associated with 3 other letters. I want an automated way to paste this into 2 columns in a new sheet, like this:

A
B

A
C

D
E

F
G

F
H

F

A
2
B
C

D
1
E

F
3
G
H
I

View 2 Replies View Related

Copy And Paste Special Values But Getting Error 'Compile Error - Expected Function Or Variable'

Feb 7, 2007

I am trying to run create a simple macro that copies and paste special values - something I have done 100's of times but for some reason I keep getting an error message - even though I recorded the macro and didnt write it by hand - see below:

Sub Macro6()
Cells.Select
selection.Copy
selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub

For which I get 'Compile Error - Expected Function or Variable'

View 6 Replies View Related

Set Variable: Object Variable Or With Block Variable Not Set

Jun 4, 2007

I have the following code (just pasting the relevant section) which crashes when it reaches the highlighted line of code. and a dialog box pops up with the text: "Object variable or With block variable not set"

Sub test()
Dim StartRng As Range
Dim Buffer As Range

Set StartRng = WorkSheets("Sheet1"),Cells(1,1)

StartRng.Activate
ActiveCell. CurrentRegion.Select

Buffer = rngStart.CurrentRegion.Copy

' I also tried the following line of code but that didn't work either
'Set Buffer = rngStart.CurrentRegion.Copy
..
...
End Sub

View 9 Replies View Related

Copy A Range And Paste It Over A Variable Range

Jul 16, 2009

I am using the code below to copy a range and paste it over a variable range.

View 4 Replies View Related

Insert Variable In Formula

Nov 3, 2009

I'm using Excel 2000/2002. I have a workbook with 12 sheets named Jan, Feb, etc.
I want to add a new sheet (Report) with formulas in various cells to get data from a cell in a particular sheet.

For instance, in a cell of the new sheet is: =Jan!D64. I want the user to be able to select a month from a drop down list and for the formula to change sheets depending on the month selected. The formula should be: =(sheet name!)D64. I tried playing with INDIRECT, but maybe couldn't get the syntax right. I can't use macros, the Excel is on a server and they are not permitted. The end user is less knowledgeable in Excel than me.

View 2 Replies View Related

Insert Row At Variable Location

Dec 3, 2009

I had a quick question for something that should be simple but I can't figure it out. I have a column of sorted values, it goes

A
A
A
A
A
B
B
B
B
B

and I want to insert a row to separate the A's from the B's. But there will be a random number of A's. I can figure out how to count where the A's end. But I can't figure out how to insert a row. Any suggestions? I tried the two below but they don't seem to work. The for section is counting the A's, and it works, it's what comes next that's giving me a headache!

View 2 Replies View Related

Insert Variable Graphic

Dec 5, 2006

I have a folder of numbered graphic files (500 odd) and want to insert the correct graphic in a spreadsheet depending on the value of a cell (the value will be the graphic name). Thus everytime the cell value changes, the correct graphic file will appear.

View 9 Replies View Related

Copy / Paste After Specific Number Of Rows

Jul 18, 2013

I have a code which is copy/pasting the selection specified number of times

VB:
Sub CopyNtimes()
Dim i
For i = 1 To Application.InputBox("How many times do you want to copy the selection?", "", 1, Type:=1)
With Selection
.Copy .Offset(i * .Rows.Count)
End With
Next
End Sub

How to modify this code so that it can paste the selection specified number of times leaving specified number or rows

For Example:

Selection is A1:Z10
need to copy paste 2 times...
Rows to leave: 3

So it should paste in the range A14:Z24 and then A28:Z38

View 5 Replies View Related

Variable Columns How To Insert Formula

Mar 25, 2009

I have to work on sheets with variable columns.

So for eg Col A Col B Col C Col D are fixed and then there are variable no of columns - Col E Col F and so on....

I have to insert columns after the last colum ie in Col F in this case.

However, the new column (lets call it Col G) will give a value with formula that connects Col E value with Col B (fixed)value. Again Col H (another new col) will also give a value with formula connecting Col H with Col B(fixed).

Easy to do in normal scenario but when I record macro in excel ( i cannot write VB), the variable columns make it difficult.

View 9 Replies View Related







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