Добрый день! Есть макрос, который копирует ячейки из отфильтрованного диапазона одной таблицы в отфильтрованный диапазон другой (фильтры настроены одинаково). Данные переносятся вместе с форматом ячеек и самого текста. Необходимо добавить условие, чтобы ячейка переносила и примечание к ней при копировании. Тестовая табличка во вложении (в данном примере перенос с листа1 на лист 2). Помогите с решением, пожалуйста.
Код:
Sub PasteToVisible()
Dim copyrng As Range, pasterng As Range
Dim cell As Range, i As Long
'запрашиваем у пользователя по очереди диапазоны копирования и вставки
Set copyrng = Application.InputBox("Диапазон копирования", "Запрос", Type:=8)
Set pasterng = Application.InputBox("Диапазон вставки", "Запрос", Type:=8)
'проверяем, чтобы они были одинакового размера
If pasterng.Cells.Cells.Count <> copyrng.Cells.Count Then
MsgBox "Диапазоны копирования и вставки разного размера!", vbCritical
Exit Sub
End If
'переносим данные из одного диапазона в другой только в видимые ячейки
For Each cell In pasterng
If cell.EntireRow.Hidden = False Then
cell.Value = Cells(cell.Row, copyrng.Column).Value
cell.Interior.Color = Cells(cell.Row, copyrng.Column).Interior.Color
cell.Font.Color = Cells(cell.Row, copyrng.Column).Font.Color
cell.Borders(xlEdgeBottom).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).LineStyle
cell.Borders(xlEdgeBottom).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).Weight
cell.Borders(xlEdgeBottom).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).Color
cell.Borders(xlEdgeRight).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).LineStyle
cell.Borders(xlEdgeRight).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).Weight
cell.Borders(xlEdgeRight).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).Color
cell.Borders(xlEdgeLeft).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).LineStyle
cell.Borders(xlEdgeLeft).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).Weight
cell.Borders(xlEdgeLeft).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).Color
cell.Borders(xlEdgeTop).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).LineStyle
cell.Borders(xlEdgeTop).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).Weight
cell.Borders(xlEdgeTop).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).Color
cell.Font.Name = Cells(cell.Row, copyrng.Column).Font.Name
cell.Font.Size = Cells(cell.Row, copyrng.Column).Font.Size
cell.Font.Bold = Cells(cell.Row, copyrng.Column).Font.Bold
cell.Font.Italic = Cells(cell.Row, copyrng.Column).Font.Italic
End If
Next cell
End Sub
Код:
Sub PasteToVisible()
Dim copyrng As Range, pasterng As Range
Dim cell As Range, i As Long
'запрашиваем у пользователя по очереди диапазоны копирования и вставки
Set copyrng = Application.InputBox("Диапазон копирования", "Запрос", Type:=8)
Set pasterng = Application.InputBox("Диапазон вставки", "Запрос", Type:=8)
'проверяем, чтобы они были одинакового размера
If pasterng.Cells.Cells.Count <> copyrng.Cells.Count Then
MsgBox "Диапазоны копирования и вставки разного размера!", vbCritical
Exit Sub
End If
'переносим данные из одного диапазона в другой только в видимые ячейки
For Each cell In pasterng
If cell.EntireRow.Hidden = False Then
cell.Value = Cells(cell.Row, copyrng.Column).Value
cell.Interior.Color = Cells(cell.Row, copyrng.Column).Interior.Color
cell.Font.Color = Cells(cell.Row, copyrng.Column).Font.Color
cell.Borders(xlEdgeBottom).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).LineStyle
cell.Borders(xlEdgeBottom).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).Weight
cell.Borders(xlEdgeBottom).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeBottom).Color
cell.Borders(xlEdgeRight).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).LineStyle
cell.Borders(xlEdgeRight).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).Weight
cell.Borders(xlEdgeRight).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeRight).Color
cell.Borders(xlEdgeLeft).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).LineStyle
cell.Borders(xlEdgeLeft).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).Weight
cell.Borders(xlEdgeLeft).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeLeft).Color
cell.Borders(xlEdgeTop).LineStyle = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).LineStyle
cell.Borders(xlEdgeTop).Weight = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).Weight
cell.Borders(xlEdgeTop).Color = Cells(cell.Row, copyrng.Column).Borders(xlEdgeTop).Color
cell.Font.Name = Cells(cell.Row, copyrng.Column).Font.Name
cell.Font.Size = Cells(cell.Row, copyrng.Column).Font.Size
cell.Font.Bold = Cells(cell.Row, copyrng.Column).Font.Bold
cell.Font.Italic = Cells(cell.Row, copyrng.Column).Font.Italic
End If
Next cell
End Sub