Copy data from 1 sheet and paste in another sheet.

Vasanth88ece

New Member
Joined
Feb 26, 2025
Messages
2
Office Version
  1. 365
Platform
  1. 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
 

Attachments

  • Screenshot (3).png
    Screenshot (3).png
    133.9 KB · Views: 5

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top