![]() |
#1
|
|||
|
|||
![]()
have written following macro to paste copied data to just visible cells. It fails to work for the cells which are immediately after a hidden cell. (See the attachment, if I copy range A1:c1 from “ rowdata sheet” and then select range c1:f1 from “pastdata”sheet, when running the code, I expect c1 value of “ rowdata sheet” sheet be pasted to f1 in “pastdata” sheet but it is pasted on c6 in the “pastdata”sheet instead.
Can you guide me on this issue? Sub pasttojustvisblecells() Application.DisplayAlerts = False Dim ws As Worksheet Dim rng As Range Dim rng1 As Range Dim n As Integer Dim i As Integer Dim ws1 As Worksheet Set ws = ActiveSheet Set rng = Selection.SpecialCells(xlCellTypeVisible) n = rng.SpecialCells(xlCellTypeVisible).Cells.Count MsgBox rng.Address Sheets.Add After:=ActiveSheet Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Set rng1 = Selection Set ws1 = ActiveSheet For i = 1 To n ws1.Activate rng1.Cells(i).Select Selection.Copy ws.Activate rng.Cells(i).Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Next i ws1.Activate ActiveSheet.Delete ws.Activate Application.DisplayAlerts = True End Sub |
Tags |
hidden, paste |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
LSLSLS | Word VBA | 2 | 01-07-2022 05:46 AM |
for visible cells (filtered), how find value lowest than 4.00 and return the cell number | murfy69 | Excel | 6 | 08-03-2017 12:03 AM |
VBA color of visible gridlines of tables word (with some merged cells in first rows) | Alvaro.passi | Word VBA | 0 | 07-18-2017 09:11 AM |
Losing rows when pasting split cells | Gitley | Word Tables | 1 | 01-15-2013 07:49 AM |
In Excel 2007-After Selecting Visibe Cells-How do I "Copy to Visible cells" Only | mag | Excel | 0 | 10-28-2012 08:04 PM |