Hello,
I have a problem in copy pasting records which match a user defined criteria. A user can define a criteria and hit 'run' button. Records which match criteria are copied from a different sheet (same workbook) and should be pasted into a table on the active sheet without spaces. There are 55 columns.
I have the following code, but for some reason it only brings out the first matching record only. Help!
'Module to search all Wards' records that match a Ward name specified in the drop-down menu
Sub findward()
Dim wardname As String
Dim finalrow As Integer
Dim i As Long
Sheets("Ward_rank_table").Range("B7:BC157").ClearContents
wardname = Sheets("Ward_rank_table").Range("B3").Value
finalrow = Sheets("Ward_rank_set").Range("B160").End(xlUp).Row
Sheets("Ward_rank_set").Select
For i = 2 To finalrow
If Cells(i, 2) = wardname Then
Range(Cells(i, 2), Cells(i, 55)).Copy
Sheets("Ward_rank_table").Select
Range("B7").End(xlUp).Offset(1, 0).Resize(1, 55).PasteSpecial xlPasteFormulasAndNumberFormats
End If
Next i
Range("B3").Select
I have a problem in copy pasting records which match a user defined criteria. A user can define a criteria and hit 'run' button. Records which match criteria are copied from a different sheet (same workbook) and should be pasted into a table on the active sheet without spaces. There are 55 columns.
I have the following code, but for some reason it only brings out the first matching record only. Help!
'Module to search all Wards' records that match a Ward name specified in the drop-down menu
Sub findward()
Dim wardname As String
Dim finalrow As Integer
Dim i As Long
Sheets("Ward_rank_table").Range("B7:BC157").ClearContents
wardname = Sheets("Ward_rank_table").Range("B3").Value
finalrow = Sheets("Ward_rank_set").Range("B160").End(xlUp).Row
Sheets("Ward_rank_set").Select
For i = 2 To finalrow
If Cells(i, 2) = wardname Then
Range(Cells(i, 2), Cells(i, 55)).Copy
Sheets("Ward_rank_table").Select
Range("B7").End(xlUp).Offset(1, 0).Resize(1, 55).PasteSpecial xlPasteFormulasAndNumberFormats
End If
Next i
Range("B3").Select