返回列表 上一主題 發帖

新增與查找程式修改

回復 1# shootingstar
  1. Sub 轉寫()
  2.     Dim motoHani As Range, sakisht As Worksheet, sakrng As Range
  3.     Set motoHani = [F3].Resize(7)
  4.     If IsError(Application.Match([F2], [B3:B8], 0)) Then MsgBox "沒有 型號!! ": Exit Sub
  5.     If [F5] = "" Then MsgBox "沒有 入出庫單號!! ": Exit Sub
  6.     Set sakisht = Worksheets([F2].Value)
  7.     Set sakrng = sakisht.Range("A" & Rows.Count).End(xlUp).Offset(1)
  8.     sakrng.Resize(, 7).Value = Application.Transpose(motoHani)
  9.     MsgBox "輸入完畢"
  10. End Sub
  11. Sub 查找()
  12.     Dim motoHani, myRng As Range
  13.     Set motoHani = [F3].Resize(7)
  14.     If IsError(Application.Match([F2], [B3:B8], 0)) Then MsgBox "沒有 型號!! ": Exit Sub
  15.     If [F5] = "" Then MsgBox "沒有 入出庫單號!! ": Exit Sub
  16.     Set myRng = Sheets([F2].Value).Columns(3).Find([F5], LookAt:=xlWhole)
  17.     If myRng Is Nothing Then MsgBox "沒有符合條件的資料!":   Exit Sub
  18.     Set myRng = Sheets([F2].Value).Cells(myRng.Row, 1)
  19.     Set myRng = myRng.Resize(, 7)
  20.     motoHani.Value = Application.Transpose(myRng)
  21. End Sub
複製代碼

TOP

回復 3# sheau-lan
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     查找 "查找"   'xlword 參數
  4.     查找 "刪除"   'xlword 參數
  5. End Sub
  6. Sub 查找(xlword As String)   'xlword 傳遞的參數 為 "查找" 或 "刪除"
  7.     Dim motoHani, myRng As Range
  8.     Set motoHani = [F3].Resize(7)
  9.     If IsError(Application.Match([F2], [B3:B8], 0)) Then MsgBox "沒有 型號!! ": Exit Sub
  10.     If [F5] = "" Then MsgBox "沒有 入出庫單號!! ": Exit Sub
  11.     Set myRng = Sheets([F2].Value).Columns(3).Find([F5], LookAt:=xlWhole)
  12.     If myRng Is Nothing Then MsgBox "沒有符合條件的資料!":   Exit Sub
  13.     Set myRng = Sheets([F2].Value).Cells(myRng.Row, 1)
  14.     If xlword = "查找" Then                           'xlword 傳遞的參數 為 "查找"
  15.         Set myRng = myRng.Resize(, 7)
  16.         motoHani.Value = Application.Transpose(myRng)
  17.     ElseIf xlword = "查找" Then                       'xlword 傳遞的參數 為 "刪除"
  18.         myRng.Resize(, 7).Delete Shift:=xlUp          '在這裡刪除資料
  19.     End If
  20. End Sub
複製代碼

TOP

回復 5# sheau-lan
最後加上
  1. [F2].Resize(8) = ""
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 不要小看自己,因為人有無限的可能。
返回列表 上一主題