返回列表 上一主題 發帖

[發問] 如何讓表單自動產生財產編號??

[發問] 如何讓表單自動產生財產編號??

各位高手及版大好

  表單再新增後會產生時間,選擇資產類別後,財產編號要如何自動帶到下個一編號呢??因為資產類別有分,如何依照資產類別去抓下一個編號呢!!!求解 拜託



20180412.zip (21.62 KB)
yvonne

回復 6# Hsieh

感謝超級版主*20000,這段CODE我需要好好研究,,,真的非常感謝...
yvonne

TOP

回復 7# afu9240


    表單自動產生財產編號 (自動儲存).zip (27.88 KB)

了解看看,不懂再問
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 5# iamaraymond


    i 大 感謝  受教了~~解決這項問題
yvonne

TOP

回復 1# afu9240
  1. Private Sub ComboBox3_Change()
  2. With 工作表1
  3. n = Application.CountIf(.[A:A], ComboBox3 & "*")
  4. TextBox1.Text = ComboBox3 & Format(n + 1, "0000")
  5. End With
  6. End Sub

  7. Private Sub CommandButton1_Click() '新增輸入
  8.     Dim x As Integer
  9.     TextBox11.Text = Date
  10.     CommandButton1.Visible = False
  11.     CommandButton9.Visible = True
  12. End Sub

  13. Private Sub CommandButton2_Click() '結束系統
  14.     End
  15. End Sub

  16. Private Sub CommandButton9_Click() '儲存
  17.      Dim CT As Control
  18.    
  19. For Each CT In Controls
  20.    If CT.Parent.Name = "Page1" And CT.Name Like "*Box*" Then
  21.       If CT = "" Then MsgBox "資料未填": Exit Sub
  22.    End If
  23. Next
  24. ar = Array(TextBox1, ComboBox3, ComboBox1, TextBox3, TextBox4, TextBox5, TextBox6, TextBox8, ComboBox2, TextBox9, "", TextBox7, TextBox10, "", TextBox11)
  25. With 工作表1
  26. .Cells(.Rows.Count, 1).End(xlUp).Offset(1).Resize(, UBound(ar) + 1) = ar
  27. End With
  28. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 4# afu9240

會有這個錯是因為當你按下"儲存"時,所以格子都被清空,所以觸動到combobox3_change,但此時combobox3裡面沒有值
所以解決方法就是,判斷若combobox3裡沒有值,就不執行程式
  1. Private Sub ComboBox3_Change()
  2. If ComboBox3.Text = "" Then Exit Sub
  3.     With Worksheets(1).Range("A:A")
  4.         Set c = .Find(ComboBox3.Text, LookIn:=xlValues, SearchDirection:=xlPrevious)
  5.         If Not c Is Nothing Then
  6.             TextBox1.Text = ComboBox3.Text & Format(Val(Right(c.Value, Len(c.Value) - 2)) + 1, "00000")
  7.         Else
  8.             TextBox1.Text = ComboBox3.Text & "00001"
  9.         End If
  10.     End With

  11. End Sub
複製代碼
Excel VBA網頁資料收集教學:
http://forum.twbts.com/thread-20848-1-1.html

TOP

回復 3# naruto018


    非常感謝n大提供code,內容還要再深入了解,但這邊先跟n大請教一下,

  在選擇 combobox3資產類別選項後,財編會自動帶出,但按儲存後有出現下面畫面,(資料有存入到工作表1),

yvonne

TOP

回復 1# afu9240

參考看看
  1. Private Sub ComboBox3_Change()
  2.     With Worksheets(1).Range("A:A")
  3.         Set c = .Find(ComboBox3.Text, LookIn:=xlValues, SearchDirection:=xlPrevious)
  4.         If Not c Is Nothing Then
  5.             TextBox1.Text = ComboBox3.Text & Format(Val(Right(c.Value, Len(c.Value) - 2)) + 1, "00000")
  6.         Else
  7.             TextBox1.Text = ComboBox3.Text & "00001"
  8.         End If
  9.     End With

  10. End Sub
複製代碼

TOP

有人可以教我一下嗎>??
yvonne

TOP

        靜思自在 : 有智慧才能分辨善惡邪正;有謙虛才能建立美滿人生。
返回列表 上一主題