+ Reply to Thread
Results 1 to 7 of 7

Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sheet1

  1. #1
    Registered User
    Join Date
    05-09-2014
    Location
    Denver, CO
    MS-Off Ver
    Excel 2013
    Posts
    4

    Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sheet1

    I hope that I can explain this problem correctly. What I am trying to do is type a specific computer model in sheet1. The in turn. Will start a search in sheet2 that has all the models in column A. This will copy the Yes/No answer from sheet2 column B to the correct column in sheet1. Very new to VB coding and macros. Im thinking I need a loop that will do a search and copy. Than a secondary set of code to past. Every time I try something. I FUBAR my excel sheets. Can do formulas decently. But I dont think a formula is the way to go. Thank you for your help.

    Sheet1
    Column B
    Model (lable of column B)
    HP T610 (Thin Endpoint)
    HP DC 5100
    MAC G3 (example computer)

    Column D
    Win 7 Compatible?(Lable of column C)
    Yes
    No
    ? (Need to populate this column with Yes/No from sheet2)

    Sheet2
    Column A
    Model
    HP T610 (Thin Endpoint)
    HP DC 5100
    MAC G3 (Need to search and find this model from sheet1)

    Column B
    Win 7 Compatible?
    Yes
    No
    No (Need this to transfer to Sheet1 column D)
    Last edited by semperfresh; 05-09-2014 at 03:33 PM.

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    Where you are new to macros but "decent" at formulas, is there a specific reason to do this in VBA? It seems to me that, for someone who is decent with formulas, this should be a relatively simple VLOOKUP() function or other lookup function.
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Registered User
    Join Date
    05-09-2014
    Location
    Denver, CO
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    I do mostly math formulas not so much a search and copy from one sheet to another. The reason for a macro. Is that going threw allot of the forums here. It appears as the best method for this issue. Since the list will be changing and being added to. But no matter what I try. I just cant get it down. I mostly deal with hardware. So adding how many video cards to desktops(Example) is what I mainly do with excel. This is a new task for me and I am completely lost. Thank you for replying.

    I have been bouncing from excelforum.com, microsofts website and another website (not sure if I should say the name.) Trying to learn this. Not as easy as I thought.
    Last edited by semperfresh; 05-09-2014 at 03:30 PM.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    I do mostly math formulas not so much a search and copy from one sheet to another.
    You are like me in this respect -- learned how to do math in a spreadsheet before you learned how to do lookups.

    Without more detail, I'm not convinced that a macro is the best method. I would suggest you start with the VLOOKUP() function (http://office.microsoft.com/en-us/ex...011.aspx?CTT=1) =VLOOKUP(B2,sheet2!$A$2:$B$2000,2,false) where B2 contains the lookup value. For a variable size database, I will usually just set the lookup_table argument to be larger than the largest data set I expect to see.

    Unless there is more to this, this seems to me that this should do the job.

    On edit: If you have cross - posted this somewhere, we would like to know where (see form rules about cross-posting). That way, if you find your solution elsewhere, we can know that and stop trying to find a solution to a problem someone else has helped you solve.

  5. #5
    Registered User
    Join Date
    05-09-2014
    Location
    Denver, CO
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    I don't think I cross posted. I found allot of copy and past whole columns from one sheet to another and what not. But nothing about doing a search, then copy and past a single cell from one sheet to another. Finding out to do a search was probably the easiest thing to find. Thank you for your help. I'm going to try your suggestion. I truly appreciate your help.

  6. #6
    Registered User
    Join Date
    05-09-2014
    Location
    Denver, CO
    MS-Off Ver
    Excel 2013
    Posts
    4

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    Ok here is the code that I came up with. The only problem is you have to type the exact case that is in sheet2. Not everybody is adding new names the same. Im trying to add a wild card (EX. *) for the search. This way you can type three characters (or more) and find the correct or all that deal with that fild of search. For ex. B*B*, would bring back Bob or Billy.

    Sub Compatable()
    '
    ' Compatable Macro
    '
    Dim start_sheet As String, start_row_location As String, start_cell_value As String
    Dim search_counter As Long, search_sheet As String, temp As String
    '
    start_sheet = ActiveSheet.Name
    start_row_location = ActiveCell.Row
    start_cell_value = ActiveCell.Value
    ' This tab should NOT be renamed without changing this vatiable to match.
    search_sheet = "Workstation List"
    '
    ' Start code
    temp = Range("B" + (CStr(start_row_location))).Value
    If temp = "" Then
    MsgBox "Model is Blank"
    GoTo 500
    End If
    '
    ' selects Workstation List sheet to search for the Model
    Sheets(search_sheet).Select
    '
    ' Find the model type
    '
    search_counter = 1
    '
    Do Until Range("A" + (CStr(search_counter))).Value = ""
    '
    If UCase(Range("A" + (CStr(search_counter))).Value) = UCase(start_cell_value) Then
    Worksheets(start_sheet).Range("D" + start_row_location).Value = Worksheets(search_sheet).Range("B" + (CStr(search_counter))).Value
    '
    GoTo 500
    End If
    search_counter = search_counter + 1
    Loop
    '
    ' returns to starting sheet
    Sheets(start_sheet).Select
    '
    MsgBox "No Match for """ + start_cell_value + """"
    '
    500:
    ' returns to starting sheet
    Sheets(start_sheet).Select
    End Sub

  7. #7
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: Trying to type in sheet1 that will search sheet 2 and return answer from sheet 2 to sh

    If you really want to do this in VBA, you might consider looking at the FIND method (http://msdn.microsoft.com/en-us/libr...ice.15%29.aspx) and/or how to use Excel's lookup functions in VBA (http://msdn.microsoft.com/en-us/libr...ice.11%29.aspx).

+ 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. =+Sheet1!A1+Sheet1!B1+Sheet1!C1 macro to convert all linked ref to Values
    By chriszoma in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2013, 02:44 PM
  2. Copy certain data from Sheet1 to Sheet 2 based on values in a column on Sheet1
    By theglitch in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2013, 01:28 PM
  3. Compare Sheet1 and Sheet 2 and Remove Matching Records from Sheet1
    By MotoDave in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-21-2013, 12:35 PM
  4. merge book1,sheet1,book2,sheet1,book3,sheet1 ect
    By cfinch100 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-11-2013, 01:30 PM
  5. [SOLVED] I need a formula to return a column of data from sheet1 into sheet 2
    By DustOfTheEarth in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-15-2013, 06:36 PM

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