I have two sheets "Data" - which has raw data and "Report" - as Report form .
- Report sheet first 5 rows has info.
- Data Sheet there 6 columns of Data available (SlNo Name Desig Place gender Category)
- Report sheet has first 5 columns only (SlNo Name Desig Place gender)
- Report sheet range C5 is dropdown box (List from Category column of Data sheet).
So based on this C5 value get details from Data sheet and paste in Report sheet.
I tried the following code but it pastes the whole row when I want to paste only Name,Desig,Place,gender details in offset and loop...
Sub ViewBtn()
Dim SCHL As String
Dim x As Long
x = 2
Do While Cells(x, 1) <> ""
Sheets("Report").Range(Cells(x, 1).Address, Cells(x, 5).Address).ClearContents
x = x + 1
Loop
Dim id As String
id = ActiveSheet.Range("C5").Value
x = 2
Sheets("Data").Select
Category = id
Do While Cells(x, 1) <> ""
If Cells(x, 4) = Category Then
Worksheets("Data").Rows(x).Copy
Worksheets("Report").Activate
erow = Sheets("Report").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ActiveSheet.Paste Destination:=Worksheets("Report").Rows(erow)
End If
Worksheets("Data").Activate
x = x + 1
Loop
Application.CutCopyMode = False
Worksheets("Report").Activate
End Sub
Worksheets("Data").Rows(x).Copy
Search around and see how to copy certain columns within the row. – dev1998Copy
statement to just copy columns B:E - e.g.Worksheets("Data").Rows(x).EntireRow.Range("B1:E1").Copy
orWorksheets("Data").Range("B" & x & ":E" & x).Copy
. There are many, many more examples on the internet of copying certain cells rather than whole rows that I am surprised that you managed to find aRows(x).Copy
before you found what you were looking for. – YowE3K