Loop Through Columns And Sum Them At Bottom

Nov 17, 2008

I've been working on coding a summary sheet that pulls data from
worksheets in the active workbook.

I'm almost done, but am stumped at writing some code that will loop
through the columns that I have copied and total them. I recorded a
macro, but nothing happened when I ran it.

What I have now is this code snippet that I found which works
perfectly when I put my cursor in the active cell.
I am not sure how I should write it into my sub.

code that I found that works:

Set rng1 = ActiveCell.End(xlDown)
Set rng2 = rng1.End(xlUp)(2, 1)
rng1(3, 1).Formula = _
"=Sum(" & Range(rng2, rng1).Address(False, False) & ")"

I tried this:

For Each col In NewSh
ColNum = ColNum + 1
Range(RwNum, ColNum).Select

Set rng1 = ActiveCell.End(xlDown)
Set rng2 = rng1.End(xlUp)(2, 1)
rng1(3, 1).Formula = _
"=Sum(" & Range(rng2, rng1).Address(False, False) & ")"

Next col

View 9 Replies


ADVERTISEMENT

Loop Through A Range From Bottom To Top

Sep 30, 2013

I tend to use a lot of For Each loops when I want to go through a range looking for something but this time I'm not so sure it will work.

I have 9 databases each containing over 400 rows with different pieces of client information, these databases are shared between around 40 people (I've also used the 'Allow users to edit ranges' utility to restrict access). What this means however is that the users cannot delete an entire row, instead they can only 'clear contents' on individual cells. This is fine until I try to generate statistics from the databases using autofilters which stop at the first blank row.

So I need to write a backwards for each statement that starts at the bottom and deletes all the blank rows on the way up to the top. I've tried similar things to this before using the For Each but when you use it to delete a row it sometimes skips the next row as it continues at the next one.

I've not managed to get it to work before, I'm just looking for a little guidance really as to how to do this correctly.

VB:
For TopRow = 1 To BottomRow = Range("A1").SpecialCells(xlCellTypeLastCell).Row Step -1
'If is blank delete row.....
Next

View 1 Replies View Related

Loop Range Of Cells. Top To Bottom, Left To Right

Nov 7, 2006

I have a spreadsheet which is going to be populated everyday from figures from another spreadsheet using autofilters and the very useful SubTotal worksheet function. I'll attach a copy of the work in progress, also there will be a macro in here which Everytime the user presses update, it copies a range of cells and formatting and pastes it to the next available cell on the right. I've also drawn the movement of the cells i'd like The reason being, is that its going to give day to day, up to date figures from a datasheet.

The problem i have is that when i come to populate the grid which has been copied, i need a calculations to populate each cell in the Less<1week column, then when it gets to the bottom, move Back to the top, and accross to the right 1, and then populate down again, and so on until the end of the grid in question, i dont think i can use a for/next loop becuase it will be a different column address everytime. I dont really like loops, but i feel this needs it.

View 6 Replies View Related

Function Macro Debug: Continue Onto The Do Loop At The Bottom That Does All The Work

Aug 9, 2006

I am having a problem with a custom funciton I am trying to create. It will exit after it is finished with the IF Then Else statement. I need it to continue onto the Do loop at the bottom that does all the work.

Function UPCECheck( num As String) As Long
Dim CheckNum As Long
Dim TempCheck As Long
Dim X As Long
Dim Holdtxt As Variant
UPCECheck = 0
CheckNum = 0
Debug.Print Len(num)
If Len(num) = 12 Then
Holdtxt = num
ElseIf Len(num) < 12 Then
Holdtxt = "000000000000" & num
Holdtxt = Val(Mid(Holdtxt, Len(holdtext) - 12, 12))
End If...................

View 6 Replies View Related

Merging One Columns Data To The Bottom Of Another

Jan 24, 2009

Give me the code to attached one column of data to the bottom of another?
ie the next available cell

so column a has 250 lines of data the data from another column will then go diectly into 251

thats not the number i want but the next available

View 13 Replies View Related

Add Like Text Totals Of Columns At Bottom Of Column

Jul 2, 2009

Note that the "Fruit" and "Fruit Totals" column letter position will always be different every time I run the macro, so I would like the macro to find these columns by name rather than by column letter.

I'd like a macro that adds the total number of fruits in the "Fruit" column by looking doing 2 things...

1. Add the total number of "Fruits" in the "Fruit" column, find the bottom-most row of data in the "Fruit" column, go down 2 rows, and create the text named "Fruits Total"

2. In the cell directly to the right of "Fruits Total" put the value of the total number of fruits in this cell (which will be in the "Fruit Totals" column)

3. Add the total number of "Apples" in the "Fruit" column, find the bottom-most row of data in the "Fruit" column, go down 2 rows, and create the text named "Apples Total"

4. In the cell directly to the right of "Apples Total" put the value of the total number of apples in this cell (which will also be in the "Fruit Totals" column)

5. Repeat steps 3 & 4 for the other fruits

Best to show you an example ...

View 14 Replies View Related

Loop Through Columns And Row?

Aug 16, 2014

I want to perform double_click event for combobox, but only for cells in certain columns and rows.

this is code :

[Code] ....

I have to loop through columns 6 to 67 with step 1, and rows 19 to 409 with step 5, but don't know how . I attached sample, coloured cells needs that double_click event.

Attached File : Loop_Column_Row.xls

View 12 Replies View Related

Loop To Run Through Columns

Apr 15, 2008

I am having some problems in setting up a macro that is intended to do the following

Run for every cell in a collumn a check if cell =2
If true then B1 is copied to that cell.
If false then nothing

This seems rather simple but the loop should go to collumn B, C, D, E, F,... until the last collumn.

Every time the collumn shfits the cell to be copied also shifts so is B1, C1, D1, E1, F1,...

View 14 Replies View Related

VBA - Loop Through Columns

May 12, 2011

I have a data set that I need to reorganise

Currently the data runs across the columns as:

COL A:C = Descriptions
ROW 1:1 = Week End dates
ROW 2:2 = Week Number
and D3:BC122 = Values
AccData

[code].....

What I need to do is create some VBA that will loop through E:BC moving the data in the column to under the data in Col C each time (and also A:C)

I can create loops that add 1 to row number but am stuck adding 1 to column in VBA.

View 7 Replies View Related

Loop On Two Columns?

Apr 5, 2013

I have two columns of data J2:K1000, I need loop through both columns at the same time and copy the data into cells into E1 and F2, then run through the remainder of the code. The code below I have adapted but cannot get it to work correctly.

HTML Code:

Sub Test()
Dim LastRowColJ, LastRowColK As Long
Sheets("Sheet1").Select
LastRowColJ = Range("J65536").End(xlUp).Row
For Each c In Worksheets("Sheet1").Range("J2:J" & LastRowColJ).Cells
Sheets("Sheet1").Range("E1").Value = c
For Each d In Worksheets("Sheet1").Range("K2:K" & LastRowColJ).Cells

[code]....

View 4 Replies View Related

Loop Columns

Aug 21, 2009

my worksheet has columns e1:il100 populated with data. what i am trying to do, is to insert a column to the right of column 'e', copy the contents of cell 'e1', to rows 3:100. then i want to cut e3:f100, and place it in the next available row in columns b:c, delete columns e:f, and then goto the next populated column, which i believe is now column e, and start over, until all columns have been moved to columns b:c.

View 9 Replies View Related

Loop Through Columns

May 3, 2007

I have a dataset with has 12 columns of data followed by 49 columns of values (one for each product) What I need (to be able to pivot it) is one column of values. I had written a quick for each loop but this doesnt work for colums:

Sub Adjust()
' Find last cell populated by data
Range("A65535").End(xlUp).Select
Last_Cell = ActiveCell.Row
'Rename a column heading
Range("M1").Value = "Partner"
Range("M2:M" & Last_Cell).ClearContents
'Loop through each column and copy data values
For Each Column In Range("N:BJ")
' Find first empty cell
Range("N65535").End(xlUp).Select
Start_Cell = ActiveCell.Row + 1.....................

View 2 Replies View Related

How To Create Loop Through Among Columns

Apr 30, 2012

i would like to create loop throug among columns, is xlup or xldown methods will make sensne ?

View 2 Replies View Related

Loop Through All Columns Of A Worksheet

Nov 22, 2006

I am OK to set values to the third row of "Loop Folder" from a column in " T" but I haven't figured out how to capture the remaining 22 columns of this worksheet.

Workbooks("Loop Folder.xls").Sheets("Sheet1"). Range("A3").FormulaR1C1 = Workbooks("B .xls").Sheets(" T").Range("C5").FormulaR1C1

Workbooks("Loop Folder.xls").Sheets("Sheet1").Range("B3").FormulaR1C1 = Workbooks("B .xls").Sheets(" T").Range("C6").FormulaR1C1

Workbooks("Loop Folder.xls").Sheets("Sheet1").Range("C3").FormulaR1C1 = Workbooks("B .xls").Sheets(" T").Range("C16").FormulaR1C1.............

View 3 Replies View Related

Loop Through All Columns In All Sheets

Nov 28, 2006

I am trying to loop all columns in each of a number of sheets using current region.

It selects the current region OK but the column counter only shows 1 as the number of columns in any sheet.

The Cells(6,1) likely has something to do with it but I do not know any other way to point to the current region I need. I do not know in advance how many rows or columns I am starting with but each has the required Row 6.

For x = 1 To Sheets.Count

Sheets(x).Activate
Cells(6, 1).CurrentRegion.Select
Selection.CurrentRegion.Name = "Mydata"

'Loop all columns in sheet

For y = 1 To Range("MyData").End(xlToRight).Column
Cells(5, y).Select

Next y

Next x

View 6 Replies View Related

Concatenate With Loop Through 2 Columns Of Information

May 28, 2014

I have a list of names with blank cells in Column A cell 2.

I want the programme to scroll through this column until it finds a name, when it does I want it to look in cell offset(1, 1), in this case B3 to see if there is a number. I want this number to be moved to offset (0, 1) AND any subsequent numbers below it until the next blank cell in that column (B).

In the attached image cell B2 will contain all numbers in cells B3:B9 with a / between them. Cell B10 will have number from B11 and B12 will have B13:B15. If there is no number it will just continue to the next name in column A. My rough code below delivered the first number only in the relevant cell and I'm not clever enough to get it right. It does not have to be super slick as it's for one time use.

I need numbers in column B cleared as they are concatenated into the single cell.

Spreadsheet.jpg

View 12 Replies View Related

Running A Loop On A Few Columns Simultaneously

Feb 13, 2010

I am trying to run a loop on a few columns simultaneously, from the last row to the top (well, until the 2nd row).

So I have a few columns of data, A through I, and the number of rows they populate changes all the time.

So how would I run a loop that will check for the following:

If a certain row in Column F is greater than the previous row in column F by 1.5times, then in that same row, if number in Column B is greater than number in E, the code should put the the value of E in a new column, lets say M (in the same row)

I know that sounds very confusing, but is that even possible? I am playing with loops, and I can only do very simple loops where I define a range, like

View 14 Replies View Related

Select Columns To Merge Within For Loop

Nov 18, 2011

My issue is I want to use a for loop to go through a spreadsheet. Within the for loop if a certain condition is true I want it to select all columns from A to AW and merge them together.

Example of what I have so far:

Sub MergeHeaders
dim i as Intger, LastRow as Integer
LastRow = Cells(Rows.Count, "CP").End(xlUp).Row
For i = 1 to LastRow
'Check if the leading character is a letter, not number
If Asc(Cells(i, "AP")) > 64 Then
'I want select from A to AW only for current row i, then merge
end If
next i
end sub

View 1 Replies View Related

Loop Based On Number Of Columns

Jan 10, 2014

I have a table of data (lets say A2:H30) i want to populate so i want the macro to loop based on how many columns i have? I am using this to post the data based on # of rows..

Sheets("Main Cal").Select Dim bottomA As Integer
bottomA = Range("D" & Rows.Count).End(xlUp).Row
Dim c As Range
Dim ws As Worksheet
For Each c In Range("D3:D" & bottomA)
Set ws = Nothing
On Error Resume Next
Set ws = Worksheets(c.Value)
On Error GoTo 0
If ws Is Nothing Then

View 1 Replies View Related

How To Loop Through Specific Columns And Rows

Mar 25, 2014

I am stuck with looping columns and rows.What i am trying to do is... I have to loop through columns E3 to G3 and also rows of each column and check for a condition inside the column.How can i achieve that? I have the following structure.. How can i code it?

For i=E3 to G3 'Column loop
for j=4 to 47 'Row loop
'code to check if the value isnumber
next j
next i

View 9 Replies View Related

Loop Copy Columns Action

Sep 6, 2009

I need to copy several columns (G:L) underneath (A:F)
I got this going using the recorder, and copy the action several times in the macro (See below).

I obviously would like to have this in a loop.

Range("G1:L35000").Select
Selection.Copy
Range("A65536").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Columns("G:L").Select
Application.CutCopyMode = False....................

View 9 Replies View Related

How To Loop Through Dynamic Ranges Using Columns Rather Than Rows

Jun 23, 2014

I have a list of several hundred columns, beginning with column "G:G", with varying numbers of rows of data in column - each row dipicting a monthly data point. I'd like to average the numbers in each column (need to average over the appropraite time-frame) and compare that average with the corresponding average (same time-frame) for benchmark (column"F:F"). The problem is I don't have the same number of data points in each column; some have data points for every month for the past 33 years, and some just a few years; almost all have differing beginning and ending dates as well.

[Code] ....

View 9 Replies View Related

Loop Through Rows And Return Matching Columns

Jan 9, 2009

I have a worksheet with 2 columns. The first column contains names and the second column contains numbers associated with the name.

How can I specify a name, go through the sheet to find all the occurances of that name and then paste all the numbers associated with that name in another worksheet in a set position.

View 9 Replies View Related

Make A Mcaro Loop Through 5 Pairs Of Columns

Jan 26, 2009

I've managed to get my macro to work ok - but what I want to do now is to get it to loop through more columns. Currently it looks for email addresses in column AH (which will always be the same) then it looks for a "yes" in columnAB and if there is no "SENT" in column T then it sends an email,after which it adds the word "SENT" to column T. What I want t do is for the macro to then run on columns AC+U, AD+V, AE+W and AF+X. So basically it will loop through one column to the right each time for a total of 5 pairs of columns

View 2 Replies View Related

Nested Loop To Concatenate 2 Columns Of Data

Oct 27, 2009

I think I just need a basic Nested For Loop code. I have a list of in column A, from A1:A537 and another list in column B, for B1:B50. I want to add a column that concatenates, each item in Column A to B1 (so 537 rows), then again each item in Column A to B2, another 537 rows, etc.. this loop is repeated 50 times, one for each name in column B.

View 3 Replies View Related

Modify Loop To Copy A Range Not Whole Columns

Nov 21, 2013

I have the following code that rearranges the data based on the values in the first column (cannot post attachments). Currently, the code is grabbing the whole columns when performing cut and paste and with larger sets of data I am getting "Excel cannot complete this task with available resources" error. Need to modifying the code so it only grabs the used range as opposed to the whole columns.

Code:

Sub ArrangingColumnsByNumber()
Dim Count As Long
Dim CurrentNumber As Long
Dim CurrentColumn As Long
Count = 1
CurrentColumn = 1
CurrentNumber = Cells(Count, CurrentColumn)

[code].....

View 4 Replies View Related

Average Loop - Calculate Result Separately For Columns

Nov 15, 2012

I've been trying to loop data for column A from row 1 until 6 and print the result on specified cell. But the problem is, it keeps looping until column B,C and D.

I want to calculate average result separately for column B,C, and D without taking the previous data.

Here is the code that I've done.

VB:
Sub Avg()
col = 1
Row = 1
Do
Name = ThisWorkbook.Sheets("Sheet2").Cells(Row, col).Value
If Name <> "#" Then

[Code] ....

I attached my excel. The green box indicate the result that I want : function.xls

View 5 Replies View Related

VBA Macro To Loop Text To Columns Through All Rows Of Data?

Apr 17, 2014

I am trying to get a macro to run in excel that takes a simple text to columns command in one line of data and runs the command on a loop through however many rows of data there happen to be.

I've attached two screenshots - one with what I've got now (Before.jpg) and what I'd like to have after the macro runs (After.jpg). The code below is what I used to get the first text to column breakout, which I can hopefully run on a loop to breakout anything in the DEPT column that contains a "/". It can ignore the rows that only have one department to begin with.

Selection.TextToColumns Destination:=Range("K2"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1)), TrailingMinusNumbers:=True

Eventually I'll want to create another macro that transposes the breakout text back into the DEPT column and populates it with the corresponding data, but I figure I'll take things one step at a time.

Attached Images
Before.jpg‎
ter.jpg‎

View 10 Replies View Related

Loop To Increment Column Width Of Range Of Columns?

May 22, 2014

I'm trying to use the following loop to increment the column width of a range of columns thus:

Code:
NewWidth = 0
WidthIncrement = 0.5
For MyCount = 1 To 26
NewWidth = NewWidth + WidthIncrement
Cells(1, MyCount).EntireColumn.ColumnWidth = NewWidth
Next

If I set WidthIncrement to be an integer value, the code works correctly. If, however, I make it something like 0.1, all the column widths that the loop acts on are set to 0. I suspect it's something to do with how I'm declaring the NewWidth and WidthIncrement variables - they're currently set to Double. I know that I can have decimal values for column widths (e.g. 8.43)

View 5 Replies View Related

Loop Is Supposed To Stop When The Cell That Is 4 Columns To The Left

Aug 29, 2008

The loop is supposed to stop when the cell that is 4 columns to the left, in the workbook named "Complete DSS", changes numbers.

/ This is the cell ref. / This is the original
Do While ActiveCell.Offset(0, -4) = ThisTape

The number will stay the same for a while until it changes tapes, then it Should stop when they are no longer equal.

It used to work, but maybe some recent changes have messed up the function.

Sub Compare_printout_2_WDMS()
Application.ScreenUpdating = False
Dim ray, sht As Worksheet, Exist As Boolean
Dim BookA
Dim I As Long
I = Worksheets.Count

AreaNum = InputBox("¿Que es el Area?")
ThisTape = Range("C8").Value
ActiveWorkbook.SaveAs Filename:="C:Documents and Settingssmith27DesktopArea 319 printoutsArea " & AreaNum & " " & ThisTape & ".xls"

Columns("A:A").insert
LR = ActiveSheet.Range("B65536").End(xlUp).Row..........................

View 9 Replies View Related







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