ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   R/T Error encounter - Posted originally to functions ng - in error (https://www.excelbanter.com/excel-programming/319571-r-t-error-encounter-posted-originally-functions-ng-error.html)

Jim May

R/T Error encounter - Posted originally to functions ng - in error
 
Sub SumByEmployee()
Dim MyPick As String
Dim mTotal As Double
Dim rngemp As Range
mTotal = 0
MyPick = InputBox("What Employee Do you Want?")
Set rngemp = Range("C6:C15") 'list of employees - single names
For Each c In rngemp
If c = MyPick Then
mTotal = mTotal + rngemp.Offset(, -1).Value 'R/T error happens here
End If
Next c
Range("B18").Value = mTotal
End Sub

Thanks for any help!!



Jim May

R/T Error encounter - Posted originally to functions ng - in error
 
I think I got it; changed line to:
mTotal = mTotal + c.Offset(, -1).Value


"Jim May" wrote in message
news:dq0zd.9985$jn.6753@lakeread06...
Sub SumByEmployee()
Dim MyPick As String
Dim mTotal As Double
Dim rngemp As Range
mTotal = 0
MyPick = InputBox("What Employee Do you Want?")
Set rngemp = Range("C6:C15") 'list of employees - single names
For Each c In rngemp
If c = MyPick Then
mTotal = mTotal + rngemp.Offset(, -1).Value 'R/T error happens here
End If
Next c
Range("B18").Value = mTotal
End Sub

Thanks for any help!!





Don Guillett[_4_]

R/T Error encounter - Posted originally to functions ng - in error
 
try this simpler version

Sub SumByEmployee()
MyPick = InputBox("What Employee Do you Want?")
For Each c In Range("C6:C15")
If c = MyPick Then mTotal = mTotal + c.Offset(, -1)
Next c
Range("B18") = mTotal

--
Don Guillett
SalesAid Software

"Jim May" wrote in message
news:dq0zd.9985$jn.6753@lakeread06...
Sub SumByEmployee()
Dim MyPick As String
Dim mTotal As Double
Dim rngemp As Range
mTotal = 0
MyPick = InputBox("What Employee Do you Want?")
Set rngemp = Range("C6:C15") 'list of employees - single names
For Each c In rngemp
If c = MyPick Then
mTotal = mTotal + rngemp.Offset(, -1).Value 'R/T error happens here
End If
Next c
Range("B18").Value = mTotal
End Sub

Thanks for any help!!






All times are GMT +1. The time now is 04:55 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com