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
ADVERTISEMENT
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
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
View Related
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
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
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
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
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
Jan 25, 2010
Inserting Variable Number Of Rows and Populating Data
View 10 Replies
View Related
Jan 2, 2007
This works: row(x).select But this doesn't: row(x:"100").select. I also need to do substitute both beginning and end range with a variable: row(x:n).select And multiple ranges: row(x:n, a:b)
I've tried tried numerous combinations of quote marks and parentheses and nothing works. What is the proper syntax?
View 5 Replies
View Related
Sep 23, 2008
I have searched high and low for a macro that can move cell values to other worksheet based on a variable serial number. I have had limited luck with my search but nothing quite reflects my needs. Any help or suggestions would be great. The way that I envision it to work is simple to say but to hard for me to figure out. I must add that I am fair to good with macros; I am using Windows XP and Excel 2003.
Here is the concept:
-I am trying to track several vehicles, their status and there general locations using a variable serial number and an excel macro. The macro would execute the calculated data on sheet “My Taxi Cars” and the results would appear on a separate worksheet called “Location” that is in the same workbook. Please see attached.
-The serial number is comprised of a cell range starting at A2 thru L2 and then concatenates in M2 it would look something like this 123N1110011011. This serial number would allow me to do simple long-range analysis for each of the vehicles. Also in theory at the end of 30-day period I could “replay” my data.
The Breakdown for the alpha numeric serial reads like this:
1) The 123 is the number of the cab.
2) The “N” is for North, etc. and it would equate to a range of cells on a separate worksheet (“Location”).
3) The Ones and Zeros are just simple yes or no answers to the common questions in the Garage at work.
Once the macro is executed the result would be the taxis number (taxi number only, the rest of the number is stripped off) being placed the correct location based off the serial number. I have no idea if this is possible and I would like to thank you in advance for your help. Thanks.
I understand that there are about 1024 different combination's for a binary number that has ten place values. Maybe the answer is to use VLOOKUP or HLOOKUP, but then that changes my analysis scheme. But if you can just help point my nose in the right direction or show me with one example I can take it the rest of the way.
View 14 Replies
View Related
Apr 8, 2009
I have an excel spreadsheet that I am trying to format. Each time the spreadsheet is of the same format but with differing amount of numbers. I.e. sometimes it will be a set of 3, the next time might be 6.
I want to write a macro that will find a set piece of text, move it offset(-1,2) and then find the next one.
For example....
View 14 Replies
View Related
Jan 4, 2012
I am creating a macro to tidy up a large data sheet. it is a list of products as follows:
Heading1Code; Heading2date; etc
12
12
12
13
13
14
15
15
15
The blanks beneath each series of products need to be deleted but they are variable and a macro that i write is not flexible enough to remove a variable number of blank rows beneath a variable number of each product.
View 9 Replies
View Related
Feb 14, 2007
I export data from another programme into excel and have written a macro to move and format this. The number of rows of data exported will be different each time. I need to be able to print this data and want to add it to the macro. I have learnt to use this code to select this data working from the last used cell to the top
Range("a1:d1", Range("a65536:d65536").End(xlUp)).Select
Using the macro recorder for printing one of my exports I got this code
Range("A1:D53").Select
Range("D53").Activate
With ActiveSheet.PageSetup
.PrintTitleRows = ""
.PrintTitleColumns = ""
End With
ActiveSheet.PageSetup.PrintArea = ""
With ActiveSheet.PageSetup.......................
View 5 Replies
View Related
Aug 25, 2010
I am trying to build a macro to work with a template file.
The template file has set sheet numbers and names (with one exception, see 4) below).
There are close to 40 sheets in all.
Some sheets are never printed.
Some sheets are always printed.
Many sheets are printed only if they are used.
Most of the sheets are 'break out' sheets and a variable number of them will be used.
So... Here is what I'm trying to accomplish.
1) Always print Sheet4(Overview1)
2) Always print Sheet6(Overview2)
3) Print Sheets 11 thru 40 IF value in cell G50 on these sheets is > 0. Note that this cell has a name (Total) and I would like to reference the name if possible. (It could happen that further evolution of the Workbook moves the cell up or down a row.)
4) Print Sheet38(Data Sort) IF it exists. Otherwise, print Sheet1(Data).
If the information on the Data sheet is limited (eg only 1 or 2 pages), we print it off directly. If the information is more extensive, we copy it to a new sheet and sort it (Data Sort).
I can achieve 1) and 2). I'm not quite sure how to go about 3) as I'm still not very good with macro loops. 4) I haven't tackled yet.
View 3 Replies
View Related
Apr 12, 2012
Our company gets excel spreedsheets with UPC numbers. The numbers are divided in parts or columns. Sometimes it's in 2 columns; sometimes in 3; and sometimes in 4 like this:
A_____B_____C____D
023__14444__779__9
023__14442__789__7
I'd like to be able to concatenate the digits and have the entire UPC number appear in a blank column to the immediate right and go straight down the line and calculate them all. I figured out how to do this with separate macros for 2, 3, and 4 digits or columns.
Sub Combine_2_Part_UPC()
Do While ActiveCell ""
ActiveCell.Offset(0, 1).FormulaR1C1 = ActiveCell.Offset(0, -1) & ActiveCell.Offset(0, 0)
ActiveCell.Offset(1, 0).Select
Loop
End Sub
Is there a way I could do this with just one macro, by maybe selecting the digits of the first UPC number in the first row of the data to cue the macro in as to how many columns to process?
(The UPCs are in the midst of a lol of other data like product cost, so a macro probably wouldn't be able to figure out how many to calculate on its own.)
View 2 Replies
View Related
Mar 1, 2014
I work on a daily basis with spreadsheets in excel. The number of columns is the same, but every single spreadsheet has a different number of rows. I recorded this macro in a table with 1196 rows and I would like to use this macro also in other tables with a different number of rows.
Sub City2()
'
' City2 Macro
'
'
Selection.Copy
Cells.Replace What:="POMPANO", Replacement:="Pompano Beach",
[Code].......
View 12 Replies
View Related
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
May 29, 2008
I am having to copy and paste rows of data into a new worksheet where the rows sizes change and I am wanting to add a new row at the end of the pasted rows but with the sumation formula to add the relevant column
e.g copy range B14:AA17 with in this case columns E to AA holding the numerical values. Therefore I wish in cell E18 to sum the value of E14:E17 and so on ending with cell AA18 holding the sum of AA14:AA17
As these vary I have all relevant variables, Range to add sumation values to eg E18:AA18
Start Cell E14 and so on.
I tried adding "=SUM(x:d)" where x and d are vars relating the the column cell required eg x = E14 and d = E17
View 3 Replies
View Related
Nov 13, 2009
I want to create a macro that will automatrically number cells in the same column. Here is the hard part. I will never start with the same number and the range nor the increment between numbers will be the same. I will start in the same cell. And the number must look like 125+45.65
View 9 Replies
View Related
Apr 19, 2009
i want a macro that will start on D25 and enter a 1 for five rows up to D29
than change and enter a 2 starting on d30 and enter a 2 for five rows
up to D34 than change an enter a 3 up to D39 ....... on and on up D225.
View 2 Replies
View Related
Oct 10, 2009
Sheet A – is of the following format
SlNO, Item_Description, …,…
The item_description is a combination of XXX, Part_no and Part_description all clubbed randomly. ( So I cannot use text-to-columns to bifurcate them).
Now Sheet B contains the part_number as follows :
SlNos, Part_no, ….,….,
I need a macro ( a procedure / function ) in Excel-vba, which would select each part_no in sheet – B one by one, find all those rows in which it appears in Item_Description column of Sheet-A and add a comment in the next column to it.
The Vlookup function cannot be used as it is not an exact match as the part_no is embedded among other things in item_description.
View 5 Replies
View Related
Dec 29, 2008
My first sheet shows the data - a list of audits and their current status.
AuditStageAlphaIn ProgressBetaReportingCharlieCompleteDeltaCompleteOmegaPlanning
I've then used a simple count formula to add up the number by each stage and it's these numbers that I want the macro to use when determining how many rows to input.
Complete2Reporting1In Progress1Planning1
A second worksheet hosts the desired output - a simple report template, split into stages for each status type (completed, planning etc.) with the correct number of rows for each.
Completed AuditsCharlieDeltaReportingBetaAudits in ProgressAlphaAudits in PlanningOmega
So, I want the macro to ensure that we have the right number of rows for each stage, as this month will be run on a monthly basis and the stage each audit is at will change, and the number of rows required in each section will also be different.
View 9 Replies
View Related
Jun 3, 2014
create a macro that will insert a certain number of blank rows to my spread sheet. The number of rows is determined by the #of tasks calculated for that day and is in column B. For example if in column A the date is 01-07-14 and in column B it has 7, I would like 7 rows inserted with the date in column A to remain the same in all 7 rows. Ideally I would like to use this macro for every row, so if the next row down has 02-07-14 and 6, I would like it to add 6 new rows with the same date.
I have attached a copy of the spread sheet for reference.
View 4 Replies
View Related
Oct 28, 2009
I am looking for is a basic macro that will copy and paste cells down as per number of entries or rows in a particular column
As an example, lets say my static data runs in Column A, from A1 : A10.
Cells B1 through to E1 each contain a seperate formula
How would I get the range B1:E1 to be copied and pasted a number of times that corresponds to the last entry in column A (in this case A10) ?
ie VBA code that recognises that the entries end at A10 and that the range B"#":E"#" must be copied and pasted down until the last entry in Column A
View 3 Replies
View Related
Feb 19, 2010
I need the macro to put Rec sheet data for each bank in Sheet Summary under the Each bank header, the macro needs to figure out the number of rows required and adjust if necessary as the rec data is not fixed. See below examples
Rec ABCDEFG5CategoryRecAccountValue DateEntry DateTypeAmount6CITIBANKCASH AMP1WTGDPFUSD1-Oct-075-Dec-08LDR-2,203.677CITIBANKCASH IMS02WTFPT2USD24-Jun-0817-Dec-08SCR2,001.388JP MORGANCASH DESWTFPT2USDSUSP15-Sep-084-Sep-09LDR-3,608.919RBSCASH DESWTFPT2USDSUSP15-Sep-084-Sep-09LCR3,889,582.9410BOACASH DESWTFPT2USDSUSP16-Sep-0829-May-09LDR-1,557,609.9511BOACASH IMS09ZPBRKQUSD17-Sep-0817-Dec-08LCR4,554,511.1112 13 14 Excel tables to the web >> Excel Jeanie HTML 4
Summary ABCDEF6CITIBANK 7RecAccountValue DateEntry DateTypeAmount8 9JP MORGAN 10RecAccountValue DateEntry DateTypeAmount11 12RBS 13RecAccountValue DateEntry DateTypeAmount14 15BOA 16RecAccountValue DateEntry DateTypeAmount17 18 19 20 21 22 Excel tables to the web >> Excel Jeanie HTML 4
Summary ABCDEF4 5 6CITIBANK 7RecAccountValue DateEntry DateTypeAmount8CASH AMP1WTGDPFUSD1-Oct-075-Dec-08LDR-2,203.679CASH IMS02WTFPT2USD24-Jun-0817-Dec-08SCR2,001.3810 11JP MORGAN 12RecAccountValue DateEntry DateTypeAmount13CASH DESWTFPT2USDSUSP15-Sep-084-Sep-09LDR-3,608.9114 15RBS 16RecAccountValue DateEntry DateTypeAmount17CASH DESWTFPT2USDSUSP3970640060LCR3,889,582.9418 19BOA 20RecAccountValue DateEntry DateTypeAmount21CASH DESWTFPT2USDSUSP3970739962LDR-1,557,609.9522CASH IMS09ZPBRKQUSD3970839799LCR4,554,511.1123 24 25 26 Excel tables to the web >> Excel Jeanie HTML 4
View 9 Replies
View Related
Feb 20, 2009
I'm fairly new to macro's and VBA, by searching on the internet i've copied and pasted some code together into a macro.
But it ends in a Run-time error 91...
The macro opens a target .xls file in a selected folder, performs copy - paste actions from masterfile to targetfile.
Than it filters data in the targetfile sheet1 and copy's the results to the various other sheets; saves and closes the targetfile.
The next target file in the folder is opened and the actions are repeated in this second target file.
For the first target file this works smoothly; but for the second one (of a total of around 100) it does not copy the filter results to the other sheets in this workbook.
The error message i get is: "Run-time error 91:Object variable or with block variable not set."
When i hit debug it highlights the line "ActiveSheet.Next.Select" which, at least in the first file, seems ok.
View 9 Replies
View Related
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
Jul 7, 2009
When i try to run the code below i get the error message - object variable or with block variable not set-
Sub REFRESHXX()
'LIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1, Criteria1:="1"
'SET RANGE
Dim sFormula1 As String
Dim sFormula2 As String
Dim sCell1 As String
Dim sCell2 As String
Dim sSheet1 As String
Dim sSheet2 As String
Dim r As Range
Dim MyRange As Range 'for testing
With Sheets("Points")
sFormula1 = .Range("CY1").Formula
sFormula2 = .Range("CY2").Formula
End With
'FORMULA IN R1C1 STYLE
strFormula = "=IF(ISNA(VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE)),0,VLOOKUP(RC[-1],MASTER!R4C3:R17908C7,3,FALSE))"
'ENTER FORMULA IN ALL CELL RANGES
r.FormulaR1C1 = strFormula
'REDUCE TO VALUES
Dim ar As Range 'an area is a range
For Each ar In r.Areas 'areas are discrete, contiguous ranges of cells
ar.Value = ar.Value
Next ar
'UNLIST
Cells(Sheets("POINTS").Range("DD801").Value, Sheets("POINTS").Range("DD800").Value).Select
Selection.AutoFilter Field:=1
End Sub
View 9 Replies
View Related
Nov 21, 2006
I found this nice little bit of code for a date range search in column A but it will not work. Apparently i have not set a variable or something.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim startDate As String
Dim stopDate As String
Dim startRow As Integer
Dim stopRow As Integer
startDate = InputBox("Enter the Start Date: (dd/mm/yyyy)")
If startDate = "" Then End
stopDate = InputBox("Enter the Stop Date: (dd/mm/yyyy)")
If stopDate = "" Then End
startDate = Format(startDate, "dd/mm/yyyy")
stopDate = Format(stopDate, "dd/mm/yyyy")
startRow = Worksheets("sheet1").Columns("A").Find(startDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
stopRow = Worksheets("sheet1").Columns("A").Find(stopDate, _
LookIn:=xlValues, lookat:=xlWhole).Row
Worksheets("Sheet1").Range("A" & startRow & ":A" & stopRow).Select
End Sub
View 9 Replies
View Related