Copy Data to sub sheets

BABU Baru

New Member
Joined
Nov 5, 2021
Messages
15
Office Version
  1. 2016
Platform
  1. Windows
The following code works good to copy data to other sheets named in Column "A" but it copy the entire rows
I want to copy only from column A2:D2 & rows can be many.
Can any expert hear help me please?

Sub YYY2()
Dim wsRng As Range, i As Long
Application.ScreenUpdating = False

Set wsRng = Sheets("Data").Range("A1:A" & Sheets("Data").Range("A" & Rows.Count).End(xlUp).Row)
For i = 1 To ThisWorkbook.Worksheets.Count

If Worksheets(i).Name <> "Data" Then

With Worksheets(i)

With .Range("A1", .Cells(.Cells(.Rows.Count, "A").End(xlUp).Row, .Cells(1, .Columns.Count).End(xlToLeft).Column))
If .Rows.Count > 1 Then
.Offset(1).Resize(.Rows.Count - 1).ClearContents
End If
End With

End With

With wsRng
.AutoFilter 1, Worksheets(i).Name
On Error Resume Next
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Copy _
Worksheets(i).Range("A" & Worksheets(i).Rows.Count).End(xlUp).Offset(1)
On Error GoTo 0
End With

End If
Next

wsRng.AutoFilter
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try changing this line:
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Copy
to this:
.Offset(1).Resize(.Rows.Count - 1,4).SpecialCells(12).Copy
 
Upvote 0
Try changing this line:
.Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).EntireRow.Copy
to this:
.Offset(1).Resize(.Rows.Count - 1,4).SpecialCells(12).Copy
Hello Joe,
No, It didn't work at all. I think, I need to set range in copy Syntax.
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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