Find vba not working!

meakashgfx

New Member
Joined
Dec 9, 2014
Messages
33
Here is the code I tried. but it stuck in finding the cell. (Set RangeObj = Cells.find) Please check the following code:
Code:
Sub CopyFromFile()Dim MyFile As StringDim erowDim Filepath As StringFilepath = "C:\Users\Nazmul Hossain Akash\Desktop\Play Excel\Final\"MyFile = Dir(Filepath)Do While Len(MyFile) > 0    If MyFile = "zmaster.xlsm" Then    Exit Sub    End If        Workbooks.Open (Filepath & MyFile)    Range("B2:D18").Copy    Set RangeObj = Cells(1, "A")    ActiveWorkbook.Close        Set RangeObj = Cells.Find(What:=RangeObj, After:=ActiveCell, _    LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _    SearchDirection:=xlNext, MatchCase:=False)    If RangeObj Is Nothing Then MsgBox "Not Found" Else RangeObj.Select    ActiveCell.Offset(rowOffset:=2, columnOffset:=0).Activate        ActiveSheet.PasteSpecial        MyFile = DirLoopEnd Sub
Please help!!!Thanks in Advance.Nazmul Hossain Akash.
 
Try this...

Code:
Sub CopyFromFile()
Dim MyFile As String
Dim erow
Dim Filepath As String
Dim FindString As String
Dim RangeObj As Range


    Filepath = "C:\Users\Nazmul Hossain Akash\Desktop\Play Excel\Final\"
    MyFile = Dir(Filepath)
    Do While Len(MyFile) > 0
        If MyFile = "zmaster.xlsm" Then Exit Sub
        Workbooks.Open Filepath & MyFile
        Range("B2:D18").Copy
        FindString = Cells(1, "A").Value
        ActiveWorkbook.Close False
        Set RangeObj = Cells.Find(What:=FindString, After:=Cells(1), _
                                  LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, _
                                  SearchDirection:=xlNext, MatchCase:=False)
        If RangeObj Is Nothing Then
            MsgBox "Not Found", vbExclamation
        Else
            RangeObj.Offset(rowOffset:=2, columnOffset:=0).PasteSpecial
        End If
        MyFile = Dir
    Loop
End Sub
 
Upvote 0

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