2017-06-28 8 views
2

私はインベントリ目的で作成しているExcelシート/ユーザフォームを持っています。VBA Userform Single Sheetリンクされたインベントリエントリ

私のuserformの最初の機能は、フォーム上のテキストボックスからコネクタとメイトのデータを取り出して、それを自分のシートの行/セルに貼り付けることです。そのコードは正常に動作します。

2番目の機能は、コネクタとメイトを相互参照することで、部品のデータを検索または変更するときに最新の情報が得られるようにします。 これは、コネクタとメイトの作成時に行1にセルアドレスを格納することで行います。それから私が「確認」を押すと、アドレスは「=」記号が追加された独自の行内の指定されたセルにコピーされ、参照式が作成されます。

シートの1つの行は、後にメイト参照を持つコネクタ用です。次の行は、それ以降のコネクタ参照があるメイト用です。それから、次の行に移動してもう一度やります。

これは、1組の部品番号で、これ以降は他の部品番号では実行できません。 私は何が間違っていますか?

コード:

Private Sub XREFCONFIRM1_Click() 

    Dim iRow1 As Long 
    Dim iRow2 As Long 
    Dim ws As Worksheet 
    Set ws = Worksheets("1STDRAFT") 
    row_number = 4 

    iRow1 = ws.Cells.Find(What:=PART1.Text, SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole).Row 

    iRow2 = ws.Cells.Find(What:=PART2.Text, SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole).Row 

     row_number = row_number + 1 

     item_in_review = Sheets("1STDRAFT").Range("A" & row_number).Value 

    With ws 
     If item_in_review = PART1.Text Then 

     .Cells(iRow1, 15).Value = "=" & Sheets("1STDRAFT").Cells(1, 15).Value 
     .Cells(iRow1, 16).Value = "=" & Sheets("1STDRAFT").Cells(1, 16).Value 
     .Cells(iRow1, 17).Value = "=" & Sheets("1STDRAFT").Cells(1, 17).Value 
     .Cells(iRow1, 18).Value = "=" & Sheets("1STDRAFT").Cells(1, 18).Value 
     .Cells(iRow1, 19).Value = "=" & Sheets("1STDRAFT").Cells(1, 19).Value 
     .Cells(iRow1, 20).Value = "=" & Sheets("1STDRAFT").Cells(1, 20).Value 
     .Cells(iRow1, 21).Value = "=" & Sheets("1STDRAFT").Cells(1, 21).Value 
     .Cells(iRow1, 22).Value = "=" & Sheets("1STDRAFT").Cells(1, 22).Value 
     .Cells(iRow1, 23).Value = "=" & Sheets("1STDRAFT").Cells(1, 23).Value 
     .Cells(iRow1, 24).Value = "=" & Sheets("1STDRAFT").Cells(1, 24).Value 
     .Cells(iRow1, 25).Value = "=" & Sheets("1STDRAFT").Cells(1, 25).Value 

    'With ws 
      'If item_in_review = PART2.Text Then 
     .Cells(iRow2, 15).Value = "=" & Sheets("1STDRAFT").Cells(1, 1).Value 
     .Cells(iRow2, 16).Value = "=" & Sheets("1STDRAFT").Cells(1, 2).Value 
     .Cells(iRow2, 17).Value = "=" & Sheets("1STDRAFT").Cells(1, 3).Value 
     .Cells(iRow2, 18).Value = "=" & Sheets("1STDRAFT").Cells(1, 5).Value 
     .Cells(iRow2, 19).Value = "=" & Sheets("1STDRAFT").Cells(1, 8).Value 
     .Cells(iRow2, 20).Value = "=" & Sheets("1STDRAFT").Cells(1, 9).Value 
     .Cells(iRow2, 21).Value = "=" & Sheets("1STDRAFT").Cells(1, 10).Value 
     .Cells(iRow2, 22).Value = "=" & Sheets("1STDRAFT").Cells(1, 11).Value 
     .Cells(iRow2, 23).Value = "=" & Sheets("1STDRAFT").Cells(1, 12).Value 
     .Cells(iRow2, 24).Value = "=" & Sheets("1STDRAFT").Cells(1, 13).Value 
     .Cells(iRow2, 25).Value = "=" & Sheets("1STDRAFT").Cells(1, 14).Value 

      End If 
     End With 


    End Sub 

ドライブフォルダリンク:https://drive.google.com/drive/folders/0Bz4rZ9ZqoU0tbkdaQjBBZVgyRTA?usp=sharing

ファイルの直接リンク:https://drive.google.com/file/d/0Bz4rZ9ZqoU0tVmJKa0xlUXBNcGc/view?usp=sharing

フォトリンク:https://docs.google.com/spreadsheets/d/1Tzi_2gaaXypBen2Ls7p21USat8uS_qhcRDwmGQLCcXE/edit?usp=sharing

+1

このビット 'row_number = row_number + 1'は、これをループにするように見えますが、決して1にしませんでした。したがって、1つの部品番号に対して1回だけ実行され、その後停止します。 – Toast

+0

それは素晴らしいです、それを見ていただきありがとうございます!私はちょうど私のRow_numberの上に "Do"を追加し、End Withステートメントの後に "Loop until Item_In_Review =" ""を実行して、それをすべてクリアしました! ありがとう、もう一度男! – chrisleepotter

答えて

0

これはたい方のために、私のコードがどのように見えるか、今あります知っている。私は私のフォームを使用したいと思っている人を助けるために、私が提供したリンクを更新します。

Private Sub XREFCONFIRM1_Click() 

    Dim iRow1 As Long 
    Dim iRow2 As Long 
    Dim ws As Worksheet 
    Set ws = Worksheets("1STDRAFT") 
    row_number = 4 

    iRow1 = ws.Cells.Find(What:=PART1.Text, SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole).Row 

    iRow2 = ws.Cells.Find(What:=PART2.Text, SearchOrder:=xlRows, _ 
     SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole).Row 

    Do 
    row_number = row_number + 1 

     item_in_review = Sheets("1STDRAFT").Range("A" & row_number).Value 

    With ws 
     If item_in_review = PART1.Text Then 

     .Cells(iRow1, 15).Value = "=" & Sheets("1STDRAFT").Cells(1, 15).Value 
     .Cells(iRow1, 16).Value = "=" & Sheets("1STDRAFT").Cells(1, 16).Value 
     .Cells(iRow1, 17).Value = "=" & Sheets("1STDRAFT").Cells(1, 17).Value 
     .Cells(iRow1, 18).Value = "=" & Sheets("1STDRAFT").Cells(1, 18).Value 
     .Cells(iRow1, 19).Value = "=" & Sheets("1STDRAFT").Cells(1, 19).Value 
     .Cells(iRow1, 20).Value = "=" & Sheets("1STDRAFT").Cells(1, 20).Value 
     .Cells(iRow1, 21).Value = "=" & Sheets("1STDRAFT").Cells(1, 21).Value 
     .Cells(iRow1, 22).Value = "=" & Sheets("1STDRAFT").Cells(1, 22).Value 
     .Cells(iRow1, 23).Value = "=" & Sheets("1STDRAFT").Cells(1, 23).Value 
     .Cells(iRow1, 24).Value = "=" & Sheets("1STDRAFT").Cells(1, 24).Value 
     .Cells(iRow1, 25).Value = "=" & Sheets("1STDRAFT").Cells(1, 25).Value 

    'With ws 
      'If item_in_review = PART2.Text Then 
     .Cells(iRow2, 15).Value = "=" & Sheets("1STDRAFT").Cells(1, 1).Value 
     .Cells(iRow2, 16).Value = "=" & Sheets("1STDRAFT").Cells(1, 2).Value 
     .Cells(iRow2, 17).Value = "=" & Sheets("1STDRAFT").Cells(1, 3).Value 
     .Cells(iRow2, 18).Value = "=" & Sheets("1STDRAFT").Cells(1, 5).Value 
     .Cells(iRow2, 19).Value = "=" & Sheets("1STDRAFT").Cells(1, 8).Value 
     .Cells(iRow2, 20).Value = "=" & Sheets("1STDRAFT").Cells(1, 9).Value 
     .Cells(iRow2, 21).Value = "=" & Sheets("1STDRAFT").Cells(1, 10).Value 
     .Cells(iRow2, 22).Value = "=" & Sheets("1STDRAFT").Cells(1, 11).Value 
     .Cells(iRow2, 23).Value = "=" & Sheets("1STDRAFT").Cells(1, 12).Value 
     .Cells(iRow2, 24).Value = "=" & Sheets("1STDRAFT").Cells(1, 13).Value 
     .Cells(iRow2, 25).Value = "=" & Sheets("1STDRAFT").Cells(1, 14).Value 

      End If 
     End With 
      Loop Until item_in_review = "" 

    End Sub 
関連する問題