返回列表 上一主題 發帖

[發問] 餘額+textbox格式

回復 1# lifedidi
  1. Private Sub UserForm_Initialize()  '員工額度表單
  2.     名稱制定
  3. End Sub
  4. Private Sub ComboBox1_Change()
  5.     With Sheets("Sheet1")
  6.         .AutoFilterMode = False
  7.         .Range("A1").AutoFilter FIELD:=3, Criteria1:=ComboBox1
  8.         TextBox1 = ""
  9.         TextBox2 = ""
  10.         TextBox3 = ""
  11.     End With
  12. End Sub
  13. Private Sub CommandButton1_Click()  '查詢鈕
  14.     If ComboBox1.ListIndex = -1 Then Exit Sub
  15.     Dim t(1 To 2) As Date, Rng As Range
  16.     Set Rng = Sheet2.[B:B].Find(ComboBox1, LookAT:=xlWhole)
  17.     If Rng Is Nothing Then
  18.         MsgBox "名稱錯誤", vbCritical + vbOKOnly, ""
  19.        Exit Sub
  20.     End If
  21.     t(1) = Rng.Offset(, 1)
  22.     TextBox1 = Application.Text(t(1), "[hh]:mm")
  23.     t(2) = Application.Sum(Sheet1.Range("D:D").SpecialCells(xlCellTypeVisible))
  24.     TextBox2 = Application.Text(t(2), "[hh]:mm")
  25.     With TextBox3
  26.         .ForeColor = vbBlack
  27.         .Text = Application.Text(IIf(t(1) > t(2), t(1) - t(2), t(2) - t(1)), "[hh]:mm")
  28.         If t(2) > t(1) Then
  29.             .Text = "-" & .Text
  30.             .ForeColor = vbRed
  31.         End If
  32.      End With
  33. End Sub
  34. Private Sub 名稱制定()
  35.     With Sheets("SHEET1")
  36.         .Cells(1, .Columns.Count).EntireColumn.Clear
  37.         .[A1].CurrentRegion.Columns(3).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
  38.         ComboBox1.List = .Range(.Cells(2, .Columns.Count), .Cells(2, .Columns.Count).End(xlDown)).Value
  39.     End With
  40. End Sub
  41. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  42.     Sheets("Sheet1").AutoFilterMode = False
  43. End Sub
複製代碼
  1. Private Sub UserForm_Initialize() '工具額度表單
  2.     名稱制定
  3. End Sub
  4. Private Sub ComboBox1_Change()
  5.    With Sheets("Sheet1")
  6.         .AutoFilterMode = False
  7.         .Range("A1").AutoFilter FIELD:=2, Criteria1:=ComboBox1
  8.         TextBox1 = ""
  9.         TextBox2 = ""
  10.         TextBox3 = ""
  11.     End With
  12. End Sub
  13. Private Sub CommandButton1_Click()  '查詢鈕
  14.     If ComboBox1.ListIndex = -1 Then Exit Sub
  15.     Dim t(1 To 2) As Date, Rng As Range
  16.     With Sheet2
  17.         Set Rng = .[A:A].Find(ComboBox1, LookAT:=xlWhole)
  18.         If Rng Is Nothing Then
  19.             MsgBox "名稱錯誤", vbCritical + vbOKOnly, ""
  20.             Exit Sub
  21.         End If
  22.         If Rng.End(xlDown).Row <> .Rows.Count Then
  23.             Set Rng = .Range(Rng.Offset(, 2), Rng.End(xlDown).Offset(-1, 2))
  24.         Else
  25.             Set Rng = .Range(Rng.Offset(, 2), Rng.Offset(, 2).End(xlDown))
  26.         End If
  27.     End With
  28.     t(1) = Application.Sum(Rng)
  29.     TextBox1 = Application.Text(t(1), "[hh]:mm")
  30.     t(2) = Application.Sum(Sheet1.Range("D:D").SpecialCells(xlCellTypeVisible))
  31.     TextBox2 = Application.Text(t(2), "[hh]:mm")
  32.     With TextBox3
  33.         .ForeColor = vbBlack
  34.         .Text = Application.Text(IIf(t(1) > t(2), t(1) - t(2), t(2) - t(1)), "[hh]:mm")
  35.         If t(2) > t(1) Then
  36.             .Text = "-" & .Text
  37.             .ForeColor = vbRed
  38.         End If
  39.      End With
  40. End Sub
  41. Private Sub 名稱制定()
  42.     Dim E As Range
  43.     With Sheets("Sheet2").[A:A]  '汽,機 額度
  44.         For Each E In .SpecialCells(xlCellTypeConstants)
  45.             ComboBox1.AddItem E
  46.         Next
  47.     End With
  48. End Sub
  49. Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
  50.     Sheets("Sheet1").AutoFilterMode = False
  51. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 3# lifedidi
  1. TextBox1 = ActiveSheet.Range("D1").Text
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 6# lifedidi
  1.     Dim d1 As Object, d2 As Object
  2.     Dim Rng As Range
  3. Private Sub ListBox1_Change()
  4.     If ListBox1.Text = "" Then Exit Sub
  5.     arr = Filter(d2.keys, ListBox1.Value)
  6.     ListBox2.Clear
  7.     For i = 0 To UBound(arr)
  8.         ListBox2.AddItem Replace(arr(i), ListBox1.Value & "-", "")
  9.     Next i
  10.     For i = 2 To 4
  11.         UserForm1.Controls("TextBox" & i).Value = ""
  12.     Next i
  13. End Sub
  14. Private Sub ListBox2_Change()
  15.     If ListBox2.Text = "" Then Exit Sub
  16.     R = d2(ListBox1.Value & "-" & ListBox2.Value)
  17.     'ec = (Rng, 1)
  18.     For c = 3 To Rng.Rows.Count
  19.         UserForm1.Controls("TextBox" & c - 1).Value = Rng(R, c).Text
  20.     Next c
  21. End Sub
  22. Private Sub UserForm_Initialize()
  23.     Set d1 = CreateObject("Scripting.Dictionary")
  24.     Set d2 = CreateObject("Scripting.Dictionary")
  25.     With Sheets("sheet1")
  26.       Set Rng = .[A1].CurrentRegion
  27.     End With
  28.     For R = 2 To Rng.Rows.Count
  29.         mycase = "-" & Rng(R, 2)
  30.         If Trim(Rng(R, 1)) <> "" Then
  31.             myname = Trim(Rng(R, 1))
  32.             br = R
  33.             d1(myname) = R & "-" & R
  34.         Else
  35.             d1(myname) = br & "-" & R
  36.         End If
  37.         d2(myname & mycase) = R
  38.     Next R
  39.     UserForm1.ListBox1.List = d1.keys
  40. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 8# lifedidi
請詳看參考vba的說明
Format 函數則使用不同於 NumberFormat 和 NumberFormatLocal 屬性的格式代碼字串。
  1. NumberFormatLocal 屬性。
  2. 套用至 Style 物件時用 NumberFormatLocal 屬性。
複製代碼
  1. NumberFormat 屬性。   
  2. 套用至 DataLabel、DataLabels、PivotField、Style 及 TickLabels 物件時用 NumberFormat 屬性。
複製代碼
  1. Format 函數
  2. 傳回一 Variant (String),含有一個根據格式運算式來格式化的運算式。
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

哦~有點了解了!
所以還是要照大大的方式去RUN才正確,
可是大大可以稍微說明一下改變哪裡才會變時間格式 ...
lifedidi 發表於 2013/4/26 16:30
  1. MsgBox Application.Text("1900/1/2", "[hh]")
複製代碼
如要顯示正常的時間格式 用Format函數就可,
但你要的時間格式:小時的顯示   [hh]:mm ,Format函數 不可用
[hh]:mm 的格式,在儲存格上用儲存格格式指令 即可
TextBox是MSForms 的控制項,可用儲存格的Value(數值) 或 Text (格式後的字串)傳遞

ps:  回文時  請按 [回覆] 按鈕  答覆你的人才會得到通知
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 13# lifedidi
在儲存的時候都會錯誤,如何錯誤???
  1. Private Sub CommandButton4_Click()
  2.     With UserForm1
  3.         If myday <> "" And IsDate(myday) = False Then
  4.             MsgBox "您輸入的完工日期無法辨別", vbCritical + vbOKOnly, "請重新輸入"
  5.             Exit Sub
  6.         End If
  7.         .CommandButton2.Enabled = True
  8.         部門 = .ListBox1.Text
  9.         編號 = .ListBox2.Text
  10.         R = d2(部門 & "-" & 編號)
  11.         For i = 2 To 4
  12.             Sheets("SHEET1").Cells(R, i + 1).Value = .Controls("TextBox" & i).Value
  13.             .Controls("TextBox" & i).ForeColor = vbRed    '色彩常數(紅)
  14.             .Controls("TextBox" & i).BackColor = vbWhite  '色彩常數(白)
  15.             .Controls("TextBox" & i).Locked = True
  16.         Next i
  17.      '   Call UpdateBox             '***這程序是何作用
  18.       '  .ListBox1.Text = 部門      '***為何重新給值
  19.        ' .ListBox2.Text = 編號      '***為何重新給值
  20.         .CommandButton4.Enabled = False
  21.     End With
  22.     MsgBox "已經完成儲存", vbOKOnly, "請注意"
  23. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 口說一句好話,如口出蓮花;口說一句壞話如口吐毒蛇。
返回列表 上一主題