2017-01-27 7 views
1

2つのワークブックがあります。それらを "Main"と "Aux"と呼ぼう。あるワークシートの値を使用して、別のワークシートの値をチェックし、セルに戻ります。

"メイン"で実行され、 "Aux"からのデータを使用する関数を書いています。

"メイン"には、1つのワークシート上の人のリストがあります。一人一人のために、グレード> = 3のスキルを持つワークブック「Aux」をチェックし、それらを連結し、ワークブック「Main」にセルを記入したいと思います。

これまでに書いたコードです。問題は範囲が "メイン"ワークブックを参照していることであり、必要なデータは "Aux"ワークブックにあります。スキルが識別される

「AUX」の本のとき列「」「技術」

  • を持つ列Gは、一人一人の名前を保持します。誰かが私に何を把握助けることができ

    Public Function Arroz(name As String) As String 
    
        Dim rngFound As Range 
        Dim strFirst As String 
        Dim strID As String 
        Dim strDay As String 
        Dim skillsAs String 
        Dim deb As String 
        Dim deb2 As String 
    
    
        strID = "Person number one" 
        strDay = "Technical" 
        skills= "" 
    
    
        Set rngFound = Workbooks("Aux.xlsx").Sheets("Skills Mao").Columns("G").Find(strID, Cells(Rows.Count, "G"), xlValues, xlWhole) 
    
        If Not rngFound Is Nothing Then 
         strFirst = rngFound.Address 
         Do 
          deb = Cells(rngFound.Row, "A").Text 
          deb2 = Cells(rngFound.Row, "M").Value 
          MsgBox deb 
          MsgBox deb2 
          If LCase(Cells(rngFound.Row, "A").Text) = LCase(strDay) And Cells(rngFound.Row, "M").Value >= 4 Then 
           skills = skills & Cells(rngFound.Row, "D").Text & " ," 
          End If 
          Set rngFound = Columns("G").Find(strID, rngFound, xlValues, xlWhole) 
         Loop While rngFound.Address <> strFirst 
        End If 
        strLast = rngFound.Address 
        Set rngFound = Nothing 
    
        Arroz = competencies 
        Exit Function 
        End Function 
    

    :「AUX」に

  • 列Dは、DEBとDEB2がメッセージボックス

コードを使用してデバッグするために使用されている

  • 変数スキルの名前を保持します私は間違っている?

  • +0

    このコードを実行するとどうなるか教えてください。エラーメッセージが表示されますか? 'rngFound'は何かを見つけたら何も返されませんか? – CodeJockey

    +0

    このコードを実行すると、ウォーズキー "Aux"から期待していたときに、ワークシート "Main"から値を取得します – noitib

    答えて

    1

    問題は、シートを指定せずにCellsを使用することです。あなたがそうするときCellsはあなたがそれを命名したように、アクティブなシートすなわち "メイン"を参照します。このような何かを試してみてください:

    ' ------ More of your existing code above ------ 
    strID = "Person number one" 
    strDay = "Technical" 
    skills= "" 
    
    ' ----- My added snippit ----- 
    Dim shAux as Worksheet 
    Set shAux = Workbooks("Aux.xlsx").Sheets("Skills Mao") 
    Set rngFound = shAux.Columns("G").Find(strID, shAux.Cells(Rows.Count, "G"), xlValues, xlWhole) 
    

    次に、あなただけではCellsの代わりに、そのシートからセルを好きな場所shAux.Cellsを使用しています。

    +0

    これがトリックでした!どうもありがとうございました。 – noitib

    関連する問題