+ Reply to Thread
Results 1 to 12 of 12

VBA to search for a row of text, then display that row for manual data entry

  1. #1
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    VBA to search for a row of text, then display that row for manual data entry

    Hi all,
    I am getting stuck in my code and need help solving it. Here is the code:

    Option Explicit

    Sub findData()
    Dim GCell As Range
    Dim Txt$, MyPath$, MyWB$, MySheet$
    Dim myValue As String

    Dim wbMain As Workbook
    Set wbMain = ThisWorkbook

    Txt = InputBox("What Organization do you want to search for?")

    MyPath = "C:\users\DKane\My Documents\"
    MyWB = "EVHC Master Hiring Spreadsheet range find.xlsx"

    Dim ws As Worksheet
    Set ws = wbMain.Sheets("Sheet1")

    Application.ScreenUpdating = False

    Dim wbSearch As Workbook
    Set wbSearch = Workbooks.Open(Filename:=MyPath & MyWB)

    Set GCell = wbSearch.Sheets(1).Cells.Find(Txt)

    If Not GCell Is Nothing Then


    ********this is were the error seems to be *****

    Dim lCol As Long
    lCol = wbSearch.Range("A1").End(xlToRight).Column


    wbSearch.Range(Range(Range("A1"), Cells(1, lCol))).Copy ws.Range("A1")


    wbSearch.Range(Range(Cells(GCell.Row, 1), Cells(GCell.Row, lCol))).Copy ws.Range("B1")

    ws.Columns.AutoFit

    Else

    MsgBox "Org Not Found"

    below are the row headings:
    HR Contact (person who can answer questions about this org) Region Organization (Company.Location Code.Department) Location in Oracle format Job Title PT/FT Local Tax Element Benefits Code Benefits Code Comments (if multiple, how can MHRC determine what benefit code should be used?) Mailstop Internal Transfer? Payroll ID Local Tax Element Union Code Union Code Comments (if multiple, how can MHRC determine when to use which code?) Uniform Allowance PTO Date Drug Screen Provider (e.g. Quest, internal, Concentra) Sign-on bonus instructions (including under what circumstances each is used, if multiple)



    Thanks in advance for any help.

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to search for a row of text, then display that row for manual data entry

    lCol = wbSearch.Range("A1").End(xlToRight).Column
    You could try
    Please Login or Register  to view this content.
    But I don't really see why you would get an error with the original code. BTW, what is the error message and which line is highlighted when you click the debug button?

  3. #3
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    yes that is what is highlighted when I debug...

    Dim lCol As Long
    lCol = wbSearch.Range("A1").End(xlToRight).Column

  4. #4
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    I seemed to have gotten past that now but it is now highlighting below....
    wbSearch.Range(Range(Range("A1"), Cells(1, lCol))).Copy ws.Range("A1")



    Thanks for your help
    Last edited by dezkane; 01-25-2016 at 06:23 PM.

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to search for a row of text, then display that row for manual data entry

    wbSearch.Range(Range(Range("A1"), Cells(1, lCol))).Copy ws.Range("A1")
    wbSearch.Range(Range(Cells(GCell.Row, 1), Cells(GCell.Row, lCol))).Copy ws.Range("B1")
    Both of these have too many 'Range' in them. Try

    Please Login or Register  to view this content.
    If you do not already do so, I suggest that when getting code from a web page that you copy and paste as opposed to copying by retyping the code. That would eliminate any typos or miscopy on your part.
    Last edited by JLGWhiz; 01-26-2016 at 10:44 AM.

  6. #6
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    Thanks so much....seems to be highlighting the prior debug error:

    Dim lCol As Long
    lCol = wbSearch.Range("A1").End(xlToRight).Column

    I do not think it likes the range here either, but not sure what else to use.
    Thanks again

  7. #7
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    this is the error I am now receiving


    Run-time error '438':

    Object doesn't support this property or method.

  8. #8
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to search for a row of text, then display that row for manual data entry

    Just about all of your WBSearch statements are missing the worksheet reference. eg. wbSearch.Sheets("Sheet1")...etc.

  9. #9
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    so would that look like this:

    lCol = wbSearch.Range("A1").End(xlToRight).Column

    wbSearch.Sheets("Sheet1")


    wbSearch.Range(Range(Range("A1"), Cells(1, lCol))).Copy ws.Range("A1")


    wbSearch.Range(Range(Cells(GCell.Row, 1), Cells(GCell.Row, lCol))).Copy ws.Range("B1")

  10. #10
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to search for a row of text, then display that row for manual data entry

    Please Login or Register  to view this content.
    Excel is built on a parent/child object model. If you use one of the parents, you cannot skip over that parent's child to the grandchild or VBA will throw an error. One way to avoid these common code writing errors is to use variariables, like the ws variable you have in the code. That variable includes the family ancestry back to the workbook level, so the workbook does not have to be specified each time you want to reference the sheet or a range on the sheet.
    [/Code]

  11. #11
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: VBA to search for a row of text, then display that row for manual data entry

    Here is how I would write the code
    Please Login or Register  to view this content.

    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.

  12. #12
    Registered User
    Join Date
    01-25-2016
    Location
    Denver CO
    MS-Off Ver
    2010
    Posts
    7

    Re: VBA to search for a row of text, then display that row for manual data entry

    Strange it is not displaying anything but org not found even if the org is on the spreadsheet...hmmmThanks again for all of your assistance, no one in my office will attempt this, so I thought I would try. you rock!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Manual data entry in dynamical table
    By gutkinma in forum Excel General
    Replies: 2
    Last Post: 12-08-2014, 09:00 AM
  2. Manual entry of some data for loan history
    By Vince-1961 in forum Excel General
    Replies: 3
    Last Post: 05-21-2013, 08:57 AM
  3. VLOOKUP and manual data entry
    By Miss.Rubixcube in forum Excel Formulas & Functions
    Replies: 18
    Last Post: 12-14-2012, 04:39 PM
  4. Foward all manual data entry in one worksheet to another
    By amq in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-03-2012, 07:48 AM
  5. Cell with VLOOKUP allowing manual text entry aswell?
    By steve_l in forum Excel General
    Replies: 1
    Last Post: 11-22-2011, 07:12 AM
  6. Prevent Manual Data Entry
    By BRAY1980 in forum Excel General
    Replies: 1
    Last Post: 10-26-2011, 05:42 AM
  7. Replies: 0
    Last Post: 10-06-2011, 07:03 AM

Tags for this Thread

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