SunnyAlv
Active Member
- Joined
- May 23, 2023
- Messages
- 337
- Office Version
- 365
- Platform
- Windows
hello guys I'm in trouble, i hope u can help
I've seen the article from this Article and modified it in such a way, and I have one problem and I can't solve it
When VBA runs on Sheet1 it will copy the "Current Array" and paste it on the filtered Sheet2 but the problem is:
when pasting, VBA always starts pasting in the second ROW at"C2" even though I already set it in "Special Cell(Visible Row)" in the first row after filtering, should start pasting in ROW "C4" not "C2"
I've seen the article from this Article and modified it in such a way, and I have one problem and I can't solve it
When VBA runs on Sheet1 it will copy the "Current Array" and paste it on the filtered Sheet2 but the problem is:
when pasting, VBA always starts pasting in the second ROW at"C2" even though I already set it in "Special Cell(Visible Row)" in the first row after filtering, should start pasting in ROW "C4" not "C2"
VBA Code:
Sub sheet_to_sheet()
Dim ws1, ws2 As Worksheet
Dim rngA, rngB, R As Range
Dim ra, rc As Long
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")
Set rngA = ws1.Range("C2:G" & Cells(Rows.Count, "C").End(xlUp).Row)
Set rngB = ws2.Range("C2:C" & Rows.Count).SpecialCells(xlVisible)(1)
'ws2.AutoFilter.Range.Offset(1, 0).SpecialCells(xlCellTypeVisible)
ra = rngA.Rows.Count
rc = rngA.Columns.Count
ws2.Range("A1:G1").AutoFilter 7, ws1.Range("G2")
If ra = 1 Then rngB.Resize(, rc).Value = rngA.Value: Exit Sub
Set rngA = rngA.Cells(1, 1).Resize(ra, 1)
For Each R In rngA
rngB.Resize(1, rc).Value = R.Resize(1, rc).Value
Do
Set rngB = rngB.Offset(1, 0)
Loop Until rngB.EntireRow.Hidden = False
Next
Application.GoTo rngB
Application.ScreenUpdating = True
Application.CutCopyMode = False
Exit Sub
skip:
If Err.Number <> 424 Then
MsgBox "Error found: " & Err.Description
End If
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
Last edited: