Dear Sir,
Your codes copy only the last row of data to first row.
I made some modifications as follows.
Now every thing is fine.
I changed the location of this line
iRow = iRow + 1
PHP Code:
Private Sub CommandButton1_Click()
Dim c As Range
Dim sDate As Date
Dim ws As Worksheet
Dim iRow As Long
Set ws = Worksheets("weights")
sDate = Me.TextBox1.Value
Sheets("sheet2").Select
Selection.Clear
With Worksheets("Sheet2")
iRow = 1
For Each c In ws.Range("E:E")
If c.Value = sDate Then
.Cells(iRow, "A").Value = Format(ws.Cells(c.Row, "E").Value, "dd-mm-yy")
.Cells(iRow, "B").Value = ws.Cells(c.Row, "B").Value
.Cells(iRow, "C").Value = ws.Cells(c.Row, "J").Value
.Cells(iRow, "D").Value = ws.Cells(c.Row, "K").Value
.Cells(iRow, "E").Value = ws.Cells(c.Row, "G").Value
.Cells(iRow, "F").Value = ws.Cells(c.Row, "F").Value
.Cells(iRow, "G").Value = ws.Cells(c.Row, "N").Value
.Cells(iRow, "H").Value = ws.Cells(c.Row, "O").Value
.Cells(iRow, "I").Value = ws.Cells(c.Row, "M").Value
.Cells(iRow, "J").Value = ws.Cells(c.Row, "D").Value
End If
iRow = iRow + 1
Next c
End With
Unload Me
Sheets("sheet2").Activate
'sort the sheet
Cells.Select
Selection.Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
Range("E18").Select
End Sub