eydani
04-05-2018, 06:34 AM
please tell me where is problem. thanks
Sub test()
Dim mysheet As Worksheet
Dim lr As Integer
Dim selrow As Integer
Dim cat As Integer
Dim x As Integer
Dim counter As Variant
Set mysheet = ThisWorkbook.Sheets("sheet1")
lr = mysheet.Cells(Rows.Count, 1).End(xlUp).Row
selrow = Selection.Row
cat = mysheet.Cells(selrow, 1)
For x = 2 To lr
If mysheet.Cells(selrow, 1) = cat Then
counter = counter + mysheet.Cells(x, 2)
End If
Next
MsgBox "Total" &cat& "is" &counter
End Sub
Sub test()
Dim mysheet As Worksheet
Dim lr As Integer
Dim selrow As Integer
Dim cat As Integer
Dim x As Integer
Dim counter As Variant
Set mysheet = ThisWorkbook.Sheets("sheet1")
lr = mysheet.Cells(Rows.Count, 1).End(xlUp).Row
selrow = Selection.Row
cat = mysheet.Cells(selrow, 1)
For x = 2 To lr
If mysheet.Cells(selrow, 1) = cat Then
counter = counter + mysheet.Cells(x, 2)
End If
Next
MsgBox "Total" &cat& "is" &counter
End Sub