TTom
Well-known Member
- Joined
- Jan 19, 2005
- Messages
- 518
I'm tweaking the following proceedure (see below - comments point where I need code help)
The proceedure finds the location for each cell that contains my specified search criteria, then proceeds to next until all are found. As each range/location (within my search range) is found, I need some code to grab the value not from the found range/location, but a cell offset from that range/location.
Example: if the search value exist at Range("A20"), then C.Address = $A$20 during test run.
I need to make myValue equal to the value in Range("B20").... or Offset(0,1) of C.Address.
In the end I'll have a sum total of values from offset of each range found within my search range that matches my serch criteria.
***
Sub Find_mySum()
mySearch = inputbox("Enter your search criteria")
With Worksheets(1).Range("myRange")
Set C = .Find(mySearch, LookIn:=xlValues)
If Not C Is Nothing Then
firstAddress = C.Address
' thisValue = ???
' I need code here to use the range from either C.Address or firstAddress
' and make the variable "thisValue" equal to the value Offset(0,1) from the range.
Do
mySum = mySum + thisValue
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
End If
End With
MsgBox (mySum)
End Sub
The proceedure finds the location for each cell that contains my specified search criteria, then proceeds to next until all are found. As each range/location (within my search range) is found, I need some code to grab the value not from the found range/location, but a cell offset from that range/location.
Example: if the search value exist at Range("A20"), then C.Address = $A$20 during test run.
I need to make myValue equal to the value in Range("B20").... or Offset(0,1) of C.Address.
In the end I'll have a sum total of values from offset of each range found within my search range that matches my serch criteria.
***
Sub Find_mySum()
mySearch = inputbox("Enter your search criteria")
With Worksheets(1).Range("myRange")
Set C = .Find(mySearch, LookIn:=xlValues)
If Not C Is Nothing Then
firstAddress = C.Address
' thisValue = ???
' I need code here to use the range from either C.Address or firstAddress
' and make the variable "thisValue" equal to the value Offset(0,1) from the range.
Do
mySum = mySum + thisValue
Set C = .FindNext(C)
Loop While Not C Is Nothing And C.Address <> firstAddress
End If
End With
MsgBox (mySum)
End Sub