+ Reply to Thread
Results 1 to 4 of 4

Using vba to index - match to a different worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    06-11-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    3

    Using vba to index - match to a different worksheet

    Hello,
    The following code is something I've been trying to get to work for a couple of hours now.
    I'm not that great at VBA scripting as I've just been teaching myself over the last couple of weeks.
    Any help with this would be apreciated.

    The problem is that the code I've made to extract the value for "BATCH / SERIAL" that corrosponds to the "PO" from another spreadsheet (which uses =indirect() forumlae so I have to open another spreadsheet too) doesn't work It just doesn't find the value even though it's in there.

    SETUP:
    Worksheets("CONC DESCRIPTION").Select
    Cells.Select
    Selection.ClearContents
    
    DIMENSION_VARIABLES:
    Dim INPUT_VAR As Variant
    Dim RESPONSE As Variant
    SET_PO:
    INPUT_VAR = 0
    INPUT_VAR = Application.InputBox("INSERT PO", "PO")
    If INPUT_VAR = False Then
        GoTo EXIT_SUB
        Else
        If INPUT_VAR = "" Then
            MsgBox ("IS NOTHING")
            GoTo SET_PO
            Else
            If Len(INPUT_VAR) = 9 Then
                If IsNumeric(INPUT_VAR) And Val(INPUT_VAR) > 0 Then
                    Else
                    MsgBox ("NONNUMERIAL OR NOT >0")
                    GoTo SET_PO
                End If
                Else
                MsgBox ("LEN =/= 9")
                GoTo SET_PO
            End If
        End If
    End If
    
    ADD_PO:
    RESPONSE = MsgBox("PO: " & INPUT_VAR & " - CORRECT?", vbYesNo)
    If RESPONSE = vbNo Then
        MsgBox ("TRY AGAIN.")
        GoTo SET_PO
        Else
        Application.Cells(12, 1) = "PO"
        Application.Cells(12, 2) = INPUT_VAR
    End If
    
    SET_SERIAL_OR_BATCH:
    Application.Cells(13, 1) = "SERIAL/BATCH"
    Dim SERIALVPO As Workbook
    Dim SPARTRACK As Workbook
    Set SPARTRACK = Workbooks.Open("X:\A350XWB Manufacturing\General\5020 Concessions\Concession Status\Copy of A350 Rear Spar Serial Number log.xls", True, True)
    Set SERIALVPO = Workbooks.Open("X:\A350XWB Manufacturing\General\5020 Concessions\Concession Status\SERIAL V PO.xls", True, True)
    RESPONSE = Application.Match(INPUT_VAR, SERIALVPO.Worksheets("SERIAL V PO").Range("E1").EntireColumn, False)
    If (Not RESPONSE Is Nothing) Then
        Application.Cells(12, 2) = SERIALVPO.Worksheets("SERIAL V PO").Range("D" & RESPONSE).Value
        Else
        MsgBox ("SERIAL / BATCH NOT FOUND")
        SERIALVPO.Close False
        SPARTRACK.Close False
        Set SERIALVPO = Nothing
        Set SPARTRACK = Nothing
        GoTo SET_PO
       End If
    SERIALVPO.Close False
    SPARTRACK.Close False
    Set SERIALVPO = Nothing
    Set SPARTRACK = Nothing
    Cheers.

    Hutchay

  2. #2
    Registered User
    Join Date
    06-11-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Using vba to index - match to a different worksheet

    also I'm also struggling with the following:

    PUT_IN_WORD:
    
    OPEN_WORD:
    Dim wordapp As Object
    Set wordapp = CreateObject("Word.Application")
    wordapp.Visible = True
    wordapp.Documents.Open "X:\A350XWB Manufacturing\General\5020 Concessions\TEMPLATES\BLANK.doc"
    
    COPY_AND_PASTE_INTO_WORD:
    Range("A1:A10").Copy 'FIRST LINE AND DIV 1
    'PASTE UNFORMATTED TEXT
    INPUT_VAR = Application.Cells(23, 2)
    DIV = 2
    Do While INPUT_VAR > 1
        Range(Cells(3, DIV), Cells(10, DIV)).Copy
        'Paste UNFORMATTED TEXT
        DIV = DIV + 1
        INPUT_VAR = INPUT_VAR - 1
    Loop
    Range("A11:A13").Copy 'LAST 3 LINES
    'PASTE UNFORMATTED TEXT
    Range("A14:B25").Copy 'INFO TABLE
    'PASTE WITH FORMATTING
    'wordapp.Selection.PasteSpecial DataType:=wdPasteText
    'Application.CutCopyMode = False
    
    SAVE_WORD:
    wordapp.document.Save
    'SAVE as - in specific location
    It's part of the same macro.. not sure why it doesn't work

  3. #3
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Using vba to index - match to a different worksheet

    What are you expecting this line to do?

    RESPONSE = Application.Match(INPUT_VAR, SERIALVPO.Worksheets("SERIAL V PO").Range("E1").EntireColumn, False)
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  4. #4
    Registered User
    Join Date
    06-11-2012
    Location
    Bristol
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Using vba to index - match to a different worksheet

    To set "RESPONSE" as the row number in which "INPUT_VAR" is found in the column E:E of the spreadsheet "SERIAL V PO.XLS".

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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