Vasanth88ece
New Member
- Joined
- Feb 26, 2025
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hey ppl!
My Scenario : i have a dataset. Named it as a master sheet. On another sheet (same workbook i) have drop down list of a specific column values of Master sheet. I m trying to fetch the complete data from master sheet for the value in the list in another one by one automatically. I need vba code to do this. My code is below.
Option Explicit
Sub search_and_extract_singlecritera()
'1. declare and set variables
'2. clear old search values
'3. find records that match criteria and paste them to the report sheet
Dim Mastersheet As Worksheet 'where the data is copied
Dim Automatesheet As Worksheet 'where the data is pasted
Dim Code As String
Dim finalrow As Integer
Dim i As Integer
'set variables
Set Mastersheet = Sheet1
Set Automatesheet = Sheet3
Code = Automatesheet.Range("D2").Value
'clear old data from report sheet
Automatesheet.Range("A5:AO200").ClearContents 'adjust the space as required
'search and get data from Mastersheet
Mastersheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
'loop to find the matches
For i = 10 To finalrow
If Cells(i, 2) = Code Then 'if B matches the code then copy
Range(Cells(i, 2), Cells(i, 41)).Copy 'copy values from B to AJ
Automatesheet.Select 'go to Automate sheet where the data to be pasted
Range("B200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats 'find the first blank cell and paste
Mastersheet.Select
End If
Next i
Automatesheet.Select
Range("D2").Select
End Sub
My Scenario : i have a dataset. Named it as a master sheet. On another sheet (same workbook i) have drop down list of a specific column values of Master sheet. I m trying to fetch the complete data from master sheet for the value in the list in another one by one automatically. I need vba code to do this. My code is below.
Option Explicit
Sub search_and_extract_singlecritera()
'1. declare and set variables
'2. clear old search values
'3. find records that match criteria and paste them to the report sheet
Dim Mastersheet As Worksheet 'where the data is copied
Dim Automatesheet As Worksheet 'where the data is pasted
Dim Code As String
Dim finalrow As Integer
Dim i As Integer
'set variables
Set Mastersheet = Sheet1
Set Automatesheet = Sheet3
Code = Automatesheet.Range("D2").Value
'clear old data from report sheet
Automatesheet.Range("A5:AO200").ClearContents 'adjust the space as required
'search and get data from Mastersheet
Mastersheet.Select
finalrow = Cells(Rows.Count, 1).End(xlUp).Row
'loop to find the matches
For i = 10 To finalrow
If Cells(i, 2) = Code Then 'if B matches the code then copy
Range(Cells(i, 2), Cells(i, 41)).Copy 'copy values from B to AJ
Automatesheet.Select 'go to Automate sheet where the data to be pasted
Range("B200").End(xlUp).Offset(1, 0).PasteSpecial xlPasteFormulasAndNumberFormats 'find the first blank cell and paste
Mastersheet.Select
End If
Next i
Automatesheet.Select
Range("D2").Select
End Sub