View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Pman Pman is offline
external usenet poster
 
Posts: 36
Default Column totals depending on different criteria

Hi JRform,

I get a "type mismatch" error message when it tries to add the columns. I
have a couple of columns to add, and the sample data looks like the one
attached in the image below:

http://tinypic.com/view.php?pic=24vtfa1&s=2

The columns I'm trying to add up a J, L, N, P, R, T, V, X, Z, AB, AD, AF,
AG and AH.

I really really appreciate your help on this.

Thanks,

Prash

"JRForm" wrote:

Pman,

Add this code to a module and you can get your totals
ALT + F11 -open VB editor
add a module and paste the code below.

Option Explicit

Sub Pman()

Dim iLastRow As Long
Dim look4Me As String
Dim first, sec, third As Variant

iLastRow = Range("G" & Range("G:G").Rows.Count).End(xlUp).Row
'change to the column you want to search

Range("G1").Select 'go to the top of the column to begin searching

Do Until iLastRow = -1
If ActiveCell < "" Then look4Me = ActiveCell

If ActiveCell = look4Me Then
first = first + ActiveCell.Offset(0, 1)
sec = sec + ActiveCell.Offset(0, 2)
third = third + ActiveCell.Offset(0, 3)
Else
ActiveCell.Offset(0, 1) = first
ActiveCell.Offset(0, 2) = sec
ActiveCell.Offset(0, 3) = third
'reset for next pub
first = 0
sec = 0
third = 0
End If

iLastRow = iLastRow - 1
ActiveCell.Offset(1, 0).Select
Loop

End Sub