0
次のコードを試してみましたが、次の列のループとその次のテキストボックス/ラベルへのループに問題があります。 ForループFor i = 2 To lastrow
ゼロ以外の値とそれぞれの列見出しを別のテキストボックスに取り込む方法
が
For fcolumn = 9 to lcolumn
としてのようなものでなければなりません。この行の前にFor
ループを追加し、ループの列に
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
'defining the rows to be search from
For i = 2 To lastrow
fcolumn = fcolumn + 1
If ws.Cells(i, "A").Value = Val(Me.TextBox1) Then
' Get non zero values from the working row
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