返回列表 上一主題 發帖

依對話框要求寫入資料

  1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  2. Dim ar()
  3. If Target.Address <> "$L$2" Then Exit Sub
  4. x = InputBox("輸入數字", , [AA1])
  5. y = InputBox("輸入次數", , 3)
  6. Do Until x = "" Or y = ""
  7. For i = 1 To y
  8.   ReDim Preserve ar(s)
  9.   ar(s) = x
  10.   s = s + 1
  11. Next
  12. x = InputBox("輸入數字", , 123)
  13. y = InputBox("輸入次數", , 3)
  14. Loop
  15. Range([L3], Cells(Rows.Count, 12).End(xlUp)) = ""
  16. If s > 0 Then [L3].Resize(s, 1) = Application.Transpose(ar)
  17. End Sub
複製代碼
學海無涯_不恥下問

TOP

回復 7# myleoyes
  1. Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  2. Dim ar()
  3. If Target.Address <> "$L$2" Then Exit Sub
  4. x = InputBox("輸入數字", , [AA1])
  5. y = InputBox("輸入次數", , 3)
  6. Do Until x = "" Or y = ""
  7. For i = 1 To y
  8.   ReDim Preserve ar(s)
  9.   ar(s) = x
  10.   If s = Application.Max([A:A]) Then GoTo 10
  11.   s = s + 1
  12. Next
  13. x = InputBox("輸入數字", , 123)
  14. y = InputBox("輸入次數", , 3)
  15. Loop
  16. 10
  17. Range([L3], Cells(Rows.Count, 1).End(xlUp).Offset(, 11)) = ""
  18. If s > 0 Then [L3].Resize(s, 1) = Application.Transpose(ar)
  19. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 心中常存善解、包容、感思、知足、惜福。
返回列表 上一主題