+ Reply to Thread
Results 1 to 2 of 2

vba cells.find problem

  1. #1
    Registered User
    Join Date
    07-24-2007
    Posts
    1

    vba cells.find problem

    Im writing a macro that will read data from one workbook, find the data in another workbook, copy the column associated with that data, and paste it into a new sheet. Im having trouble with the cells.find function... when i record a macro the code comes out like this:

    Cells.Find(what:="Node Info: 443", After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=True).Activate
    Sheets("Sheet1").Select
    Cells.FindNext(After:=ActiveCell).Activate

    if i remove the sheet1.select line of code, it no longer works... but I dont know which sheet in the workbook the data will be on all the time so cannot include the sheet in my own code.

    now my code:

    Sub forloop()
    c = 6

    For i = 1 To 35
    Windows("Monthly DP TC - Syracuse").Activate
    Cells(i, 40).Select
    If Not IsEmpty(Cells(i, 40).Value2) Then
    mycell = ActiveCell.Value
    mySearch = "Node Info: " & mycell
    If Not UCase(Right(mycell, 5)) = "TOTAL" Then

    Windows("VoIPReady - weekly - SYRNY - TW-CentralNY 2007-07-04.xls").Activate
    Application.FindFormat.NumberFormat = "General"
    'Sheets("SYRCNYAUB").Select

    Set Z = Cells.Find(what:=mySearch, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
    False, SearchFormat:=True)

    If Not Z Is Nothing Then
    Z.Activate

    myrow = ActiveWindow.RangeSelection.Row
    Rows(myrow).Select
    Selection.Copy
    ActiveWindow.ScrollWorkbookTabs Position:=xlLast
    Sheets("Sheet1").Activate
    ActiveSheet.Range(Cells(c, 1), Cells(c, 24)).Select
    ActiveSheet.Paste
    c = c + 1

    Else
    MsgBox "Can't find " & mySearch
    End If
    End If
    End If
    Next i

    End Sub


    the problem is that the macro refuses to find the node number data using the cells.find command even though it exists on the searched workbook. It works when you provide it with the sheet that the data exists on, such as
    Sheets("Sheet1").Select
    but I do not know what sheets each node data exists on... thats why im doing a find.

    thanks.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Wrap your code with Code tags, it's much easier to read. See the link at the bottom of my post.

    Please Login or Register  to view this content.
    Last edited by royUK; 07-25-2007 at 02:48 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1