返回列表 上一主題 發帖

[發問] 儲存格內容變更後自動移到下一格

回復 1# owen06
使用物件類別
  1. 'ThisWorkbook模組
  2. Dim Ar() As New Class1 '物件類別模組 [名稱: Class1]
  3. Private Sub Workbook_Open()  
  4.     Dim E As OLEObject, i As Integer
  5.     With Sheet1
  6.         For Each E In .OLEObjects
  7.             If E.progID = "Forms.CommandButton.1" Then
  8.                 If UCase(E.Object.Caption) <> "CLEAR" And UCase(E.Object.Caption) <> "MADE" Then
  9.                     ReDim Preserve Ar(0 To i)
  10.                     Set Ar(i).Class_CommandButton = E.Object
  11.                     i = i + 1
  12.                 End If
  13.             End If
  14.         Next
  15.        Run "Sheet1.CommandButton2_Click"
  16.     End With
  17. End Sub
複製代碼
  1. Public mysize As Range    'Sheet1模組
  2. Private Sub CommandButton1_Click()
  3. k1 = [I2].Value
  4. k2 = [i3].Value
  5. Set mysize = [B2].Resize(k1, k2)
  6. mysize.clear
  7. End Sub
  8. Private Sub CommandButton2_Click()
  9. 'Dim mysize As Range
  10. k1 = [I2].Value
  11. k2 = [i3].Value
  12. Set mysize = [B2].Resize(k1, k2)
  13. With mysize
  14. .Borders.LineStyle = xlContinuous
  15. .Interior.ColorIndex = 37
  16. .VerticalAlignment = xlCenter
  17. .HorizontalAlignment = xlCenter
  18. End With
  19. mysize.Cells(1).Select
  20. End Sub
複製代碼
  1. Option Explicit  '新增物件類別模組 [自動命名: Class1]
  2. Public WithEvents Class_CommandButton As MSForms.CommandButton
  3. Private Sub Class_CommandButton_Click()
  4.     Dim i As Integer
  5.     With Class_CommandButton.Parent.mysize
  6.         .Cells(Application.CountA(.Cells) + 1) = Class_CommandButton.Caption
  7.     End With
  8. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 4# owen06
  1. Public mysize As Range   '模組頂端制定為此模組的公用變數,其他模組的程序可使用此變數
  2. 'Dim mysize As Range   '模組頂端制定為此模組的私用變數,僅此模組的程序可使用此變數,其他模組的程序不可使用此變數
  3. Private Sub CommandButton1_Click()
  4. 'Dim mysize As Range  '此程序的私用變數,僅此程序中可用  
  5. k1 = [I2].Value
  6. k2 = [i3].Value
  7. Set mysize = [B2].Resize(k1, k2)
  8. mysize.clear
  9. End Sub
  10. Private Sub CommandButton2_Click()
  11. 'Dim mysize As Range
  12. k1 = [I2].Value
  13. k2 = [i3].Value
  14. Set mysize = [B2].Resize(k1, k2)
  15. With mysize
  16. .Borders.LineStyle = xlContinuous
  17. .Interior.ColorIndex = 37
  18. .VerticalAlignment = xlCenter
  19. .HorizontalAlignment = xlCenter
  20. End With
  21. mysize.Cells(1).Select
  22. End Sub
  23. '後面的CommandButton??_Click 不在需要了
  24. Private Sub CommandButton10_Click()
  25. ActiveCell = CommandButton10.Caption
  26. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 君子立恆志,小人恆立志。
返回列表 上一主題