EXCEL VBA CHECKBOX 多選回傳值到工作表中的疑問

已過期,刪除。
2017-03-09 23:44 發佈
程式碼是錯的
一、do loop 用法錯誤
二、變數y不見了
重寫比較快

Rows("2:4").ClearContents
r = 2: c = 1

For i = 1 To 6
If Controls("checkbox" & i).Value = True Then
Cells(r, c) = Controls("checkbox" & i).Caption
If r = 4 Then
c = c + 2: r = 0
End If
r = r + 2
End If
Next
snare, 你好~

把程式碼改成這樣後
Private Sub CommandButton1_Click()
Dim r, c, i As Integer
Rows("2:4").ClearContents
r = 2: c = 1
For i = 1 To 6
If Controls("CheckBox" & i).Value = True Then Cells(r, c).Value = Controls("CheckBox" & i).Caption
If r = 4 Then
c = c + 2: r = 0
End If
r = r + 2
End If
Next

Unload Me
End Sub

---------------------------
會出現
有END IF , 卻沒有IF , 請問我哪裏放錯了嗎?

如選B,D,F , 如何照樣在A2 開始放結果?

AoLin wrote:
snare, 你好...(恕刪)


If Controls("CheckBox" & i).Value = True Then Cells(r, c).Value = Controls("CheckBox" & i).Caption


這個最後沒有 Then
AoLin wrote:
有END IF , 卻沒有IF...(恕刪)


If Controls("CheckBox" & i).Value = True Then




Cells(r, c).Value = Controls("CheckBox" & i).Caption

這是2行程式碼
原來這樣, 我再試試, 請問我那個要求跳儲存格的做法該如何實現?


chiway0331 wrote:
If Controls...(恕刪)


謝謝你的指出~
謝謝snare 大大的幫助, 問題解決了,
也麻煩各位有給意見的大大, 感謝各位
內文搜尋
X
評分
評分
複製連結
Mobile01提醒您
您目前瀏覽的是行動版網頁
是否切換到電腦版網頁呢?