VBA .Find and .FindNext Do loop problem?

tz8475

New Member
Joined
Aug 13, 2013
Messages
1
The sub below is currently working but is only running once and and exiting the loop, it should continue to loop through column "R" till the current address of "dodCell" is that of the firstaddress and then exit.
Please let me know if you need any more information

Code:
    Sub addnumber()
    'used to add ree value to Dod projects
    Dim sSht As Worksheet, dSht As Worksheet
    Dim lastrow As Integer
    Dim firstAddress As String
    Dim strSearch As String
    Dim ReeCell As Range, dodCell As Range, aRange As Range, rRange As Range, aaRange As Range
    Dim hold1Cell As Range, holdCell As Range, lastCell As Range
    Set sSht = Worksheets("Sheet1")
    Set dSht = Worksheets("Sheet2")
    Set rRange = sSht.Columns(18)
    Set aRange = sSht.Columns(1)
    Set aaRange = dSht.Columns(1)
    lastrow = sSht.Range("A" & Rows.Count).End(xlUp).Row
    strSearch = "2*"
    
        Set dodCell = rRange.Find(What:=strSearch, LookIn:=xlValues, _
                        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                        MatchCase:=False, SearchFormat:=False)
        'If something dodCell holds a value then enter loop
        If Not dodCell Is Nothing Then
            'Set lastCell to dodCell
            firstAddress = dodCell.Address
            Do
                        'Set ReeCell to the value of the Ree number
                        Set ReeCell = dodCell.Offset(0, -17)
                        'Set holdCell to the Cell that holds that Dod number in "Sheet2"
                        Set holdCell = aaRange.Find(What:=dodCell, LookIn:=xlValues, _
                                        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                        MatchCase:=False, SearchFormat:=False)
                        'Set hold1Cell to the location that the Ree Value should be
                        Set hold1Cell = holdCell.Offset(0, 9)
                        'Give hold1Cell the Ree # from ReeCell
                        hold1Cell = ReeCell.Value
                        Set dodCell = rRange.FindNext(dodCell)
         
            Loop While Not dodCell Is Nothing And dodCell.Address <> firstAddress
        End If
    End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,213,549
Messages
6,114,261
Members
448,558
Latest member
aivin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top