How to get average by cell content on VBA

user5738346

In excel, I have column 1 with tickers, and column 2 with numbers, like this:

      A  B    
1    AAA 10
2    AAA 12
3    AAA 14
4    BBB  9
5    BBB 10
6    BBB 11

I need a piece of code to calculate average BY TICKER, which means that in this case I would have AAA average : 12 and BBB average = 10, etc etc etc. Up to now all i got is this code which tries to calculate the sums, I will do the divisions later, but something's wrong:

For row = 2 to 6
Ticker = Cells(row - 1, 1)
If Cells(row, 1) = Cells(row - 1, 1) Then
sum = sum + Cells(row, 2)
Else
Cells(row, 6) = sum
sum = 0
row = row + 1
Next

I get an error saying "For is missing"

user4039065

Maybe something like this in C1.

=IF(A1<>A2,AVERAGEIF(A:A,A1,B:B),"")

        averageif_once

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the cell content of DatagridTemplateColumn in wpf datagrid?

From Dev

How get average and sum of a cell with two numbers containing a dash in the middle?

From Dev

VBA How to get the next cell address

From Dev

Cell/range as a parameter for function, and calculating average in VBA

From Dev

Get cell by its content

From Dev

Get selected cell content

From Dev

How to get a text content to a variable of a cell using onclick

From Dev

How to get VBA function in Excel to return value of active cell?

From Dev

How to get cell row from current function VBA Excel

From Dev

How to get the underlying value in an error cell in excel using VBA

From Dev

how do I get a cell's location as a range in excel vba?

From Dev

How to get the underlying value in an error cell in excel using VBA

From Dev

How to get VBA function in Excel to return value of active cell?

From Dev

How in VBA Excel get the range of arguments from formula in the cell?

From Dev

How to get the value of a cell displaying time, as text, in VBA

From Dev

QML - get tableview cell content

From Dev

access value (content) of a named cell in Excel VBA

From Dev

EXCEL VBA replacing cell's content

From Dev

VBA remove " from cell content in a range

From Dev

EXCEL VBA replacing cell's content

From Dev

VBA Code to create hyperlink using cell content

From Dev

Get the value of the cell to the right in VBA

From Dev

Get the value of the cell to the right in VBA

From Dev

How to Find Average of Numbers within a Single Cell

From Dev

Get table cell content based on content of cell in neighbourhood

From Dev

Excel-VBA macro to transform cell content into a comment of another cell

From Dev

How to get the average of grades in mysql

From Dev

how to get average of specific row

From Dev

How to reference the text in a cell in vba

Related Related

  1. 1

    How to get the cell content of DatagridTemplateColumn in wpf datagrid?

  2. 2

    How get average and sum of a cell with two numbers containing a dash in the middle?

  3. 3

    VBA How to get the next cell address

  4. 4

    Cell/range as a parameter for function, and calculating average in VBA

  5. 5

    Get cell by its content

  6. 6

    Get selected cell content

  7. 7

    How to get a text content to a variable of a cell using onclick

  8. 8

    How to get VBA function in Excel to return value of active cell?

  9. 9

    How to get cell row from current function VBA Excel

  10. 10

    How to get the underlying value in an error cell in excel using VBA

  11. 11

    how do I get a cell's location as a range in excel vba?

  12. 12

    How to get the underlying value in an error cell in excel using VBA

  13. 13

    How to get VBA function in Excel to return value of active cell?

  14. 14

    How in VBA Excel get the range of arguments from formula in the cell?

  15. 15

    How to get the value of a cell displaying time, as text, in VBA

  16. 16

    QML - get tableview cell content

  17. 17

    access value (content) of a named cell in Excel VBA

  18. 18

    EXCEL VBA replacing cell's content

  19. 19

    VBA remove " from cell content in a range

  20. 20

    EXCEL VBA replacing cell's content

  21. 21

    VBA Code to create hyperlink using cell content

  22. 22

    Get the value of the cell to the right in VBA

  23. 23

    Get the value of the cell to the right in VBA

  24. 24

    How to Find Average of Numbers within a Single Cell

  25. 25

    Get table cell content based on content of cell in neighbourhood

  26. 26

    Excel-VBA macro to transform cell content into a comment of another cell

  27. 27

    How to get the average of grades in mysql

  28. 28

    how to get average of specific row

  29. 29

    How to reference the text in a cell in vba

HotTag

Archive