Ðề: cách hiển thị theo từng dòng và cột trong textbox
Nếu không lấy ngùôn dữ liệu có sẵn thì để trống RowSource.
Sau đó dùng AddItems để thêm 1 dòng vào listbox. Phát 10 lệnh AddItem thì được 10 dòng.
Kế đến là gán giá trị cho từng ô bằng:
object.List( row, column ) = biếnsố
Trong đó row và column bắt đầu từ 0 để chỉ dòng, cột đầu tiên.
Bài tập của bạn:
Sub nn()
Dim Nobandau, Laisuat, Soky, Duno, Tienlai, TraNoGoc, C11 As Double
Nobandau = 6000
Laisuat = 0.08
Soky = 10
UserForm1.ListBox1.AddItem
UserForm1.ListBox1.AddItem
UserForm1.ListBox1.List(0, 0) = "n"
UserForm1.ListBox1.List(1, 0) = " "
UserForm1.ListBox1.List(0, 1) = "Periodic"
UserForm1.ListBox1.List(1, 1) = "Payment "
UserForm1.ListBox1.List(0, 2) = "Payment "
UserForm1.ListBox1.List(1, 2) = "Interest"
UserForm1.ListBox1.List(0, 3) = "Payment "
UserForm1.ListBox1.List(1, 3) = "Principal"
UserForm1.ListBox1.List(0, 4) = "Balance"
UserForm1.ListBox1.List(1, 4) = " "
C11 = Pmt(Laisuat, Soky, Nobandau)
Duno = Nobandau
For m = 1 To Soky
Tienlai = Laisuat * Duno
TraNoGoc = -C11 - Tienlai
UserForm1.ListBox1.AddItem
UserForm1.ListBox1.List(m+1, 0) = m
UserForm1.ListBox1.List(m+1, 1) = Round(-C11, 2)
UserForm1.ListBox1.List(m+1, 2) = Round(Tienlai, 2)
UserForm1.ListBox1.List(m+1, 3) = Round(TraNoGoc, 2)
Duno = Duno - TraNoGoc
UserForm1.ListBox1.List(m+1, 4) = Round(Duno, 2)
Next
UserForm1.Show
End Sub