0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ユーザーフォームのテキストボックスのオブジェクト名をループしてコードを省略

複数のテキストボックス内のテキストを同時に動かしたいとき

オブジェクト名を TextBox1, TextBox2, TextBox3, TextBox4 のように連番にしておくと、For next でまとめて動かせます。

ユーザーフォームのオブジェクト名.Controls(String で宣言した変数)
を For Next ステートメントの中に入れてループ

Private Sub Image1_Click()
  
  Dim i As Long
  Dim p As String
  Dim ws As Worksheet
  Set ws = Sheets("Sheet3")
  
  For i = 1 To 4
  
    p = "TextBox" & i
    ws.Cells(i + 1, 2) = UserForm1.Controls(p)
  
  Next i

ws.Cells(i + 1, 2) = UserForm1.Controls(p)
転記先のセルは2行目から始まっているため、Cells(i + 1, 2) として2行目から入るよう調整

イメージオブジェクトで作成した Qiitan をクリックして実行

テキストボックスをループ.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?