I am trying to write a VBA code where there is string mentioned in a cell(search_string as per the code). I search for that string in another Worksheet(MasterRolePLMap) and if the string matches I have to copy the entire row and paste it another worksheet(Comptetency View) . When I try to paste the value there is debug error as "To Copy All cells from one worksheet to another start from R1c1"
below is my code
Sub Click_1()
Dim key As String
Dim size As Integer
row_number = 0
search_string = Sheets("CompetencyView").Range("B5")
Sheets("CompetencyView").Activate
Sheets("CompetencyView").Unprotect Password = "ritu"
Sheets("CompetencyView").Range("A12").Select
Do
If IsEmpty(ActiveCell) = False Then
Range(ActiveCell, ActiveCell.Offset(0, 11)).Delete shift:=xlUp
End If
Loop Until IsEmpty(ActiveCell) = True 'Clearing the previous data
lastrow = Sheets("MasterRolePLMap").Cells(Rows.Count, 1).End(xlUp).Row 'No of rows in MasterRolePLMap
Do
row_number = row_number + 1
Comp_Name = Sheets("MasterRolePLMap").Range("A" & row_number)
If InStr(Comp_Name, search_string) > 0 Then
Sheets("MasterRolePLMap").Rows.Copy
Sheets("CompetencyView").Activate
Sheets("CompetencyView").Range("A1").Select
ActiveSheet.Paste
Sheets("MasterRolePLMap").Activate
End If
Loop Until Comp_Name = ""
End Sub
ActiveSheet
when you need to be pasting to aRange
. Also, your code can be, and should be, amended to get rid of every instance ofActivate
,ActiveSheet
, &Select
. See here for deets – urdearboy