Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Cells.Find vba

Status
Not open for further replies.

osx99

Technical User
Apr 9, 2003
250
GB
The following code loads up Datastor with column headings and 1 row of data from one worksheet and I want to then copy the same row from another worksheet to compare the difference

The problem I'm having is that the Cells.Find(What:=DataStor(0, 1).... is not finding & activating the correct cell in the new spreadsheet

DataStor(0,1) is a unique identifier common in both worksheets and the value is stored correcty

Any ideas?

Code:
Sub ChangeControl()


Dim DataStor(150, 2) As Variant
Dim BP_Column As Range

Erase DataStor
rowcnt = 0

  Worksheets("ORIGINAL BP").Activate
  With ActiveSheet
  colcntORIG = 0
  
        For Each BP_Column In Intersect(.UsedRange, .Range("a98:g98"))
        On Error Resume Next
                bpCellDataORIG = ""
                ActiveCell.Select
                If ActiveCell.Offset(rowcnt + 2, colcntORIG).Value <> "" Then bpCellDataORIG = ActiveCell.Offset(rowcnt + 2, colcntORIG).Value
                DataStor(colcntORIG, 0) = BP_Column
                DataStor(colcntORIG, 1) = bpCellDataORIG
                colcntORIG = colcntORIG + 1
        Next
         
    End With
    
    
    
    Worksheets("NEW BP").Activate
    With ActiveSheet
    colcntNEW = 0
    
    Cells.Find(What:=DataStor(0, 1), After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
    xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
    ).Activate
    ActiveCell.Select
    Do While colcntNEW <> colcntORIG
    bpCellDataNEW = ""
    If ActiveCell.Offset(0, colcntNEW).Value <> "" Then bpCellDataNEW = ActiveCell.Offset(0, colcntNEW).Value
    DataStor(colcntNEW, 2) = bpCellDataNEW
    colcntNEW = colcntNEW + 1
    Loop
    End With
    
End Sub
 
What does it actually do? Have you tried stepping through your code with F8?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top