Cách gán giá trị từ Textbox xuống Range (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

minhtuan55

Thành viên bị đình chỉ hoạt động
Thành viên bị đình chỉ hoạt động
Tham gia
23/3/16
Bài viết
705
Được thích
52
Chào cả nhà. Em có 1 Form gồm 20 textbox. em muốn gán giá trị từ Textbox1 đến textbox20 xuống range. Hiện tại em đang làm cách như sau mà thấy nó dài quá mà Code rất Chậm. rất mong mọi người giúp đở có cách nào Ngắn mà code chạy nhanh, em xin cảm ơn

Mã:
Private Sub CommandButton1_Click() ' nut dong y

Range("E83").Value = TextBox1.Value
Range("E84").Value = TextBox2.Value
Range("E85").Value = TextBox3.Value
Range("E86").Value = TextBox4.Value
Range("E87").Value = TextBox5.Value
Range("E88").Value = TextBox6.Value
Range("E89").Value = TextBox7.Value
Range("E90").Value = TextBox8.Value
Range("E91").Value = TextBox9.Value
Range("E92").Value = TextBox10.Value
Range("E93").Value = TextBox11.Value
Range("E94").Value = TextBox12.Value
Range("E95").Value = TextBox13.Value
Range("E96").Value = TextBox14.Value
Range("E97").Value = TextBox15.Value
Range("E98").Value = TextBox16.Value
Range("E99").Value = TextBox17.Value
Range("E100").Value = TextBox18.Value
Range("E101").Value = TextBox19.Value
Range("E102").Value = TextBox20.Value

Unload Me
End Sub

Và tương tự lấy giá trị từ Range lên textbox
Mã:
Sub dad()
         sltheocuon.TextBox1.Value = Range("B83").Value
         sltheocuon.TextBox2.Value = Range("B84").Value
         sltheocuon.TextBox3.Value = Range("B85").Value
         
         sltheocuon.TextBox4.Value = Range("B86").Value
         sltheocuon.TextBox5.Value = Range("B87").Value
         sltheocuon.TextBox6.Value = Range("B88").Value
         
         sltheocuon.TextBox7.Value = Range("B89").Value
         sltheocuon.TextBox8.Value = Range("B90").Value
         sltheocuon.TextBox9.Value = Range("B91").Value
         
         sltheocuon.TextBox10.Value = Range("B92").Value
         sltheocuon.TextBox11.Value = Range("B93").Value
         sltheocuon.TextBox12.Value = Range("B94").Value
         
         sltheocuon.TextBox13.Value = Range("B95").Value
         sltheocuon.TextBox14.Value = Range("B96").Value
         sltheocuon.TextBox15.Value = Range("B97").Value
         
         sltheocuon.TextBox16.Value = Range("B98").Value
         sltheocuon.TextBox17.Value = Range("B99").Value
         sltheocuon.TextBox18.Value = Range("B100").Value
         
         sltheocuon.TextBox19.Value = Range("B101").Value
         sltheocuon.TextBox20.Value = Range("B102").Value
         sltheocuon.Show
End Sub
 
Lần chỉnh sửa cuối:
Bạn thử cái ni xem khả dĩ hơn không:

PHP:
Private Sub UserForm_Click()
 Dim W As Integer
 ReDim Arr(1 To 999, 1 To 1)
 Dim MyCTrl As Control
 For Each MyCTrl In UserForm1.Controls
    If Left(MyCTrl.Name, 5) = "TextB" Then
        W = W + 1
        Arr(W, 1) = MyCTrl.Value
    End If
 Next MyCTrl
' MsgBox W      '
 Sheets("GPE").Cells(83, 5).Resize(W).Value = Arr()
End Sub
-=09=
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom