View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mandeep Baluja Mandeep Baluja is offline
external usenet poster
 
Posts: 25
Default Extract Data from Dataset

check this out !! Name your sheet as Dataset which contains data and name another sheet as output sheet.


Sub CopyRows()

Dim ws As Worksheet
Dim wsout As Worksheet
Dim lr As Long

Set ws = ActiveWorkbook.Sheets("dataset") 'dataset sheet
Set wsout = ActiveWorkbook.Sheets("output") 'output sheet

'Getting values in this variable
tempval = InputBox("Enter the value")

'Copying first 12 rows
ws.Rows("1:12").Copy Destination:=wsout.Range("A1")

'find last row from your Dataset sheet
lr = ws.Cells(Rows.Count, 1).End(xlUp).Row

'Filter all rows matching criteria You can adjust your columns by changing F to your defined column
ws.Range("A12:F" & lr).AutoFilter field:=1, Criteria1:=tempval
ws.Range("A12:F" & lr).SpecialCells(xlCellTypeVisible).Copy Destination:=wsout.Range("A12")

'turn off filter mode
ActiveSheet.AutoFilterMode = False

End Sub

Regards,
Mandeep baluja