Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Searching two ranges

I'm trying to iterate through range on one worksheet, and then look for a
matching name on a second worksheet where a count would be added when there's
a match. My code follows, but it's generating a Next without For error
message. Any help straightening this out would be hugely appreciated.

Ken

Public Sub sUpdateCollegeCounts()
On Error GoTo 0
Dim strCollege As String
Dim lngCount As Long
Dim Cell As Range
Dim Cell2 As Range

With ThisWorkbook.Worksheets("Respondent Profile")
For Each Cell In Range("RespondentID")
If Len(Cell.Offset(0, 1)) 0 Then
strCollege = Cell.Offset(0, 1)
Else
strCollege = "No college or non-response"
End If
Worksheets("Response by College").Activate
For Each Cell2 In Range("hColleges")
If Cell.Value = strCollege Then
Cell.Offset(1, 0) = Cell.Offset(1, 0).Value + 1
Next Cell2
Worksheets("Respondent Profile").Activate
Next Cell
End With

PROC_EXIT:
Exit Sub
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default Searching two ranges

Try this:

Public Sub sUpdateCollegeCounts()

On Error GoTo 0
Dim strCollege As String
Dim lngCount As Long
Dim Cell As Range
Dim Cell2 As Range

With ThisWorkbook.Worksheets("Respondent Profile")
For Each Cell In Range("RespondentID")
If Len(Cell.Offset(0, 1)) 0 Then
strCollege = Cell.Offset(0, 1)
Else
strCollege = "No college or non-response"
End If
Worksheets("Response by College").Activate
For Each Cell2 In Range("hColleges")
If Cell.Value = strCollege Then
Cell.Offset(1, 0) = Cell.Offset(1, 0).Value + 1
End If
Next Cell2
Worksheets("Respondent Profile").Activate
Next Cell
End With

PROC_EXIT:
Exit Sub
End Sub


RBS


"Ken Warthen" wrote in message
...
I'm trying to iterate through range on one worksheet, and then look for a
matching name on a second worksheet where a count would be added when
there's
a match. My code follows, but it's generating a Next without For error
message. Any help straightening this out would be hugely appreciated.

Ken

Public Sub sUpdateCollegeCounts()
On Error GoTo 0
Dim strCollege As String
Dim lngCount As Long
Dim Cell As Range
Dim Cell2 As Range

With ThisWorkbook.Worksheets("Respondent Profile")
For Each Cell In Range("RespondentID")
If Len(Cell.Offset(0, 1)) 0 Then
strCollege = Cell.Offset(0, 1)
Else
strCollege = "No college or non-response"
End If
Worksheets("Response by College").Activate
For Each Cell2 In Range("hColleges")
If Cell.Value = strCollege Then
Cell.Offset(1, 0) = Cell.Offset(1, 0).Value + 1
Next Cell2
Worksheets("Respondent Profile").Activate
Next Cell
End With

PROC_EXIT:
Exit Sub
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Searching two ranges

Thanks. That got me back on track.

Ken

"RB Smissaert" wrote:

Try this:

Public Sub sUpdateCollegeCounts()

On Error GoTo 0
Dim strCollege As String
Dim lngCount As Long
Dim Cell As Range
Dim Cell2 As Range

With ThisWorkbook.Worksheets("Respondent Profile")
For Each Cell In Range("RespondentID")
If Len(Cell.Offset(0, 1)) 0 Then
strCollege = Cell.Offset(0, 1)
Else
strCollege = "No college or non-response"
End If
Worksheets("Response by College").Activate
For Each Cell2 In Range("hColleges")
If Cell.Value = strCollege Then
Cell.Offset(1, 0) = Cell.Offset(1, 0).Value + 1
End If
Next Cell2
Worksheets("Respondent Profile").Activate
Next Cell
End With

PROC_EXIT:
Exit Sub
End Sub


RBS


"Ken Warthen" wrote in message
...
I'm trying to iterate through range on one worksheet, and then look for a
matching name on a second worksheet where a count would be added when
there's
a match. My code follows, but it's generating a Next without For error
message. Any help straightening this out would be hugely appreciated.

Ken

Public Sub sUpdateCollegeCounts()
On Error GoTo 0
Dim strCollege As String
Dim lngCount As Long
Dim Cell As Range
Dim Cell2 As Range

With ThisWorkbook.Worksheets("Respondent Profile")
For Each Cell In Range("RespondentID")
If Len(Cell.Offset(0, 1)) 0 Then
strCollege = Cell.Offset(0, 1)
Else
strCollege = "No college or non-response"
End If
Worksheets("Response by College").Activate
For Each Cell2 In Range("hColleges")
If Cell.Value = strCollege Then
Cell.Offset(1, 0) = Cell.Offset(1, 0).Value + 1
Next Cell2
Worksheets("Respondent Profile").Activate
Next Cell
End With

PROC_EXIT:
Exit Sub
End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Searching into Non-Contiguous ranges in a columns Don Guillett Excel Programming 2 July 15th 07 09:56 PM
Searching into Non-Contiguous ranges in a columns p45cal[_50_] Excel Programming 0 July 15th 07 06:54 PM
Searching certain ranges and stopping when finding no match [email protected] Excel Programming 4 July 5th 07 10:52 PM
Searching, matching then searching another list based on the match A.S. Excel Discussion (Misc queries) 1 December 13th 06 05:08 AM
Searching and matching the textvalues in specific column ranges gki[_12_] Excel Programming 0 July 28th 04 06:43 PM


All times are GMT +1. The time now is 08:36 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"