If Val(ob.Object.Caption) = k Then ob.Delete '題號與k值相同就刪除
End If
Next
End Sub
複製代碼
作者: caichen3 時間: 2012-3-26 16:30
感謝各位大大的回覆喔作者: caichen3 時間: 2012-3-27 16:24
本帖最後由 caichen3 於 2012-3-27 17:38 編輯
請問各位大大
我有5項需求陳述(圖1),當我按下右邊"刪除"按鈕,刪除第4項需求陳述,圖畫呈現如圖2,若希望將圖2下面選項按鈕依序往上排列該如何呢??
以下是我的程式碼:
rivate Sub CommandButton5_Click()
gyou = Selection.Row
ActiveSheet.Rows(gyou).ClearContents
Range("I1").Value = Range("I1").Value - 1
TMMPA = Range("I1").Value
aaa = Chr(65)
ccc = Chr(67)
Dim yyy As String
Dim XXX As String
Dim k As Integer
Dim ob As Object
For I = 2 To 100
XXX = I
Range(aaa + XXX).Value = ("")
Range(ccc + XXX).Value = ("")
Next
ActiveSheet.Range("A2:H200").Borders.LineStyle = XILinestyleNone
ActiveSheet.Range("A2:H200").Interior.ColorIndex = xlColorIndexNone
For R = 1 To TMMPA
yyy = R + 1
Range(aaa + yyy).Value = R
Range(ccc + yyy).Value = R
Next
ActiveSheet.Range("A2:H" + yyy).Borders.LineStyle = xlContinuous
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeBottom).Weight = xlThick
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeRight).Weight = xlThick
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeLeft).Weight = xlThick
ActiveSheet.Range("A2:A" + yyy).Interior.ColorIndex = 15
k = gyou - 1
For Each ob In ActiveSheet.OLEObjects
If ob.Name Like "OptionButton*" Then
If ob.Object.GroupName = k Then ob.Delete
End If
Next
回復 11#caichen3
你要刪除的是選取儲存格那一列的群組嗎?
For Each ob In ActiveSheet.OLEObjects
If ob.Name Like "OptionButton*" Then
If ob.TopLeftCell.Row = gyou Then ob.Delete
End If
Next
Cells(gyou, 1).Resize(, 8).Delete xlShiftUp作者: caichen3 時間: 2012-3-28 11:57
回復 13#caichen3
為什麼我選取編號4按下刪除會同時將編號4、5一起刪除呢?幫你查看控制項的群組如下 GroupName=5 有10個OptionButton控制項
請你先用 Ex 的程式調整在同一列上的OptionButton 用列號設定為同一群組
用 Ex 的程式調整後再執行你的Private Sub CommandButton5_Click()
If ob.Object.GroupName = Selection.Row Then ob.Delete
End If
Next
Selection.EntireRow.Delete '刪除整列
Ex '*** 再度的 將 在同一列上的OptionButton 用 [列號]設定為同一群組
End Sub
複製代碼
作者: caichen3 時間: 2012-3-28 19:20
本帖最後由 caichen3 於 2012-3-28 22:04 編輯
請問大大:
用 Ex 的程式調整後再執行你的Private Sub CommandButton5_Click() EX( )這段程式會該放在哪裡呢?是Private Sub CommandButton5_Click()裡面一開始的地方嗎?
接下來在Private Sub CommandButton5_Click()程式最後面的地方在執行一次EX( ) 這段程式嗎??
我嘗試放在CommandButton5_Click()程式碼前與後面,還是無法可以幫我看一下嗎,感謝:)
Private Sub CommandButton5_Click()
Dim yyy As String
Dim xxx As String
Dim k As Integer
Dim ob As OLEObject
gyou = Selection.Row
ActiveSheet.Rows(gyou).ClearContents
Range("I1").Value = Range("I1").Value - 1
TMMPA = Range("I1").Value
aaa = Chr(65)
ccc = Chr(67)
For I = 2 To 100
xxx = I
Range(aaa + xxx).Value = ("")
Range(ccc + xxx).Value = ("")
Next
ActiveSheet.Range("A2:H200").Borders.LineStyle = XILinestyleNone
ActiveSheet.Range("A2:H200").Interior.ColorIndex = xlColorIndexNone
For R = 1 To TMMPA
yyy = R + 1
Range(aaa + yyy).Value = R
Range(ccc + yyy).Value = R
Next
ActiveSheet.Range("A2:H" + yyy).Borders.LineStyle = xlContinuous
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeBottom).Weight = xlThick
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeRight).Weight = xlThick
ActiveSheet.Range("A2:H" + yyy).Borders(xlEdgeLeft).Weight = xlThick
ActiveSheet.Range("A2:A" + yyy).Interior.ColorIndex = 15
k = gyou - 1
For Each ob In ActiveSheet.OLEObjects
If ob.Name Like "OptionButton*" Then
If ob.Object.GroupName = k Then ob.Delete
End If
Next
Cells(gyou, 1).Resize(, 8).Delete xlShiftUp
For Each ob In ActiveSheet.OLEObjects
If ob.Name Like "OptionButton*" Then
ob.Object.GroupName = ob.TopLeftCell.Row
End If
Next