How to retrieve values from predefined row and a column range (Incremental) to text boxes (Incremental) such that for example value of cell “J4” populate in "textbox1" and its column heading in "Label1" , value of cell “k4” populate in "textbox2" and its column heading in "Label2" and so on ............. value of cell“BG4” populate in "textbox50" and its column heading in "Label50".
如何从预定义行和列范围(增量)中检索值到文本框(增量),例如单元格“J4”的值填充在“textbox1”中,其列标题填入“Label1”,单元格“k4”的值填充“textbox2”,其列标题位于“Label2”中,依此类推......单元格“BG4”的值填充在“textbox50”中,其列标题填入“Label50”。
I have tried the followings
我尝试了以下几点
Private Sub CommandButton1_Click()
Dim i As Long, lastrow As Long
Dim ws As Worksheet
Dim fcolumn As Long
Dim lcolumn As Long
Set ws = Worksheets("md")
lastrow = ws.Cells.Find(What:="*",
SearchOrder:=xlRows,SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
fcolumn = 9
lcolumn = 50
For i = 2 To lastrow
fcolumn = fcolumn + 1
If ws.Cells(i, "A").Value = Val(Me.TextBox_orderno) Then
If Sheets("md").Cells(i, fcolumn).Value <> 0 Then
Me.Label1 = ws.Cells(2, fcolumn)
Me.TextBox1 = Sheets("md").Cells(i, fcolumn).Value
End If
If Sheets("md").Cells(i, fcolumn).Value <> 0 Then
Me.Label2 = ws.Cells(2, fcolumn)
Me.TextBox1 = Sheets("md").Cells(i, fcolumn).Value
End If
Next
End Sub
1 个解决方案
#1
0
I'm still not sure exactly what you are doing, but see if this helps you along. It should at least show you how to dynamically refer to the names of controls which alter only in the number at the end.
我仍然不确定你到底在做什么,但看看这对你有帮助。它至少应该向您展示如何动态引用仅在末尾的数字中改变的控件的名称。
Private Sub CommandButton1_Click()
Dim i As Long, lastrow As Long
Dim ws As Worksheet
Dim fcolumn As Long
Dim lcolumn As Long
Set ws = Worksheets("md")
lastrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
fcolumn = 9
lcolumn = 50
For i = 2 To lastrow
fcolumn = fcolumn + 1
If ws.Cells(i, "A").Value = Val(Me.Controls("TextBox" & i - 1)) Then
If Sheets("md").Cells(i, fcolumn).Value <> 0 Then
Me.Controls("Label" & i - 1).Value = ws.Cells(2, fcolumn)
Me.Controls("Textbox" & i - 1).Value = Sheets("md").Cells(i, fcolumn).Value
End If
End If
Next
End Sub
#1
0
I'm still not sure exactly what you are doing, but see if this helps you along. It should at least show you how to dynamically refer to the names of controls which alter only in the number at the end.
我仍然不确定你到底在做什么,但看看这对你有帮助。它至少应该向您展示如何动态引用仅在末尾的数字中改变的控件的名称。
Private Sub CommandButton1_Click()
Dim i As Long, lastrow As Long
Dim ws As Worksheet
Dim fcolumn As Long
Dim lcolumn As Long
Set ws = Worksheets("md")
lastrow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
fcolumn = 9
lcolumn = 50
For i = 2 To lastrow
fcolumn = fcolumn + 1
If ws.Cells(i, "A").Value = Val(Me.Controls("TextBox" & i - 1)) Then
If Sheets("md").Cells(i, fcolumn).Value <> 0 Then
Me.Controls("Label" & i - 1).Value = ws.Cells(2, fcolumn)
Me.Controls("Textbox" & i - 1).Value = Sheets("md").Cells(i, fcolumn).Value
End If
End If
Next
End Sub