返回列表 上一主題 發帖

請問混合編碼我應該怎麼做

回復 1# sheau-lan
品號只會新增還是會去修改之前的??
例如: 如果修改[A6]儲存格為M4-xxx規格的品號 , 下方的存放編號要全部更新嗎??

如果不用管,可參考下面;如果要,不如建個按鈕更新全部存放編號比較適用。
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2.     Dim ar, spec, prefix, count As Long
  3.     With Target
  4.         If .Row >= 3 And .Column = 1 Then
  5.             '其它欄處理略過, 假設D欄已取得規格
  6.             '.........
  7.             spec = Cells(.Row, "D").Value
  8.             prefix = Split(spec, "-")(0)
  9.             ar = Range(Cells(1, "H"), Cells(.Row - 1, "H"))
  10.             For Each x In ar
  11.                 If prefix = Split(x, "-")(0) Then
  12.                     count = count + 1
  13.                 End If
  14.             Next
  15.             Application.EnableEvents = False
  16.             Cells(.Row, "H").Value = prefix & "-" & Replace(Cells(1, count / 4 + 1).Address(False, False), "1", "")
  17.             Application.EnableEvents = True
  18.         End If
  19.     End With
  20. End Sub
複製代碼
表達不清、題意不明確、沒附檔案格式、沒有討論問題的態度~~~~~~以上愛莫能助。

TOP

        靜思自在 : 閒人無樂趣,忙人無是非。
返回列表 上一主題