Search: | |||||

| ||||

Home » Forum » MS Office | RSS Feeds |

here i have a extremely simple question: how to write codes that can

count the sum of a column?

i've tried a circular counter but the program alwayse reported a

mismatch error.

My original code is:

Dim i as long

k = 0

For i = 2 to 100

k = k + thisworkbook.worksheets("sheet1").cells(1, i)

next i

I think you can just do something like

x = Sum(A1:A100)

not sure on the exact syntax to replace the 100 with an 'i' though.

In the past, I have typically had a problem with using the For i = 2 to 100

method, so instead, I use the following syntax.

Do While ActiveCell.Value <> ""

Perform calculation steps

Loop

is it a type mismatch between the data and the long data type?

Try declaring i as a double instead maybe?

I"ve tried the methods suggested by all of you

but it didn't help.

first of all, I declared i and k as double but still got mismatch

error.

secondly, I used the function sum(A2:A100), but it was reported that

there was a syntax error.

lastly, I wanna calculate the sums of the columns respectively, I'm

afraid using Do while activecell.value <>"" would result in a sum of

all of the cells in the worksheet.

So, I haven't had my problem resolved. But I appreciate all the

suggestions. Any more leads?

sorry I couldn;t help, still a bit new at this myself.

If you're still getting a mismatch, then mayb see if something like

this works:

Dim i as Double

dim k as Double

k = 0

For i = 2 to 100

if isNumeric(k + thisworkbook.worksheets("sheet1").cells(1, i)) then

k = k + thisworkbook.worksheets("sheet1").cells(1, i)

end if

next i

If IsNumeric(thisworkbook.worksheets("sheet1").cells(1,i)) Then

...

not as written below.

How about this,

Dim dblSum As Double

' Sum column A of Sheet1 in thisworkbook

dblSum =

Application.WorksheetFunction.Sum(ThisWorkbook.Worksheets("Sheet1").Columns(1))

I think the Mismatch error is caused by a cell containing text instead

of a number.

Also your original code loops across the columns in row 1

.cells(1, i)

whereas the question suggests you want to move down the rows in a column.

Didn't find what you were looking for?
Find more on count the sum of a column
Or get search suggestion and latest updates.

Related Topics:

- sum in columns
- Count the number of rows on a worksheet, divide the count by 15
- Copying and Pasting Values From One Column To Multiple Columns Using
- Select Columns by the Name of Column in the Header Row
- splitting textpane into two columns with a line between columns
- Write a shell program to find the sum of the series sum=1 + 3 + 5 + 7 + …+ n
- Code for Write a shell program to find the sum of the series sum=1 + 5 + 9 + ...+ n in Unix
- Create a constructor class Sum
- sum of series of natural numbers
- sum and difference of 2 bcd numbers
- Compute the sum of both positive and negative elements of an array
- Getting the sum and percentage in Excel coulmn
- sum and Multiply number and print in decimal
- Sum values entered into text boxes
- Data Sum rows not hidded
- sum formula
- how to sum the even numbers only
- Conditional Summing
- sum cells with conditional formatting color
- sum of amount deliverd group
- Calculate Total Sum
- Sum colunm total in repeater
- SUM content of rows
- custom Sum function?
- Summing a range of variable size