Here is how I would write the code
Option Explicit
Sub findData()
Dim GCell As Range
Dim Txt$, MyPath$, MyWB$, MySheet$
Dim myValue As String
Dim ws As Worksheet, sh As Worksheet
Dim wbMain As Workbook
Dim lCol As Long
Set wbMain = ThisWorkbook
Set ws = wbMain.Sheets("Sheet1")
Txt = InputBox("What Organization do you want to search for?")
MyPath = "C:\users\DKane\My Documents\"
MyWB = "EVHC Master Hiring Spreadsheet range find.xlsx"
Application.ScreenUpdating = False
Dim wbSearch As Workbook
Set wbSearch = Workbooks.Open(Filename:=MyPath & MyWB)
Set sh = wbSearch.Sheets("Sheet1")
Set GCell = sh.Cells.Find(Txt)
If Not GCell Is Nothing Then
lCol = sh.Range("A1").End(xlToRight).Column
sh.Range(Range("A1"), Cells(1, lCol)).Copy ws.Range("A1")
sh.Range(Cells(GCell.Row, 1), Cells(GCell.Row, lCol)).Copy ws.Range("B1")
ws.Columns.AutoFit
Else
Notice I moved all the Dim statements to top of the code. That makes the code easier to read and has all the memory reserved up front. Using the variable for the worksheet also reduces the length of the code statements.
Bookmarks