复制合并的单元格VBA

我试图将整个行复制到一个新的工作表上,但只复制那些年龄在20岁以上的行。

我还没有编写If语句来select这些行,但是已经编写了代码来导入数据并填写各个列,以便从出生date开始获得20岁生日。

我的问题是在导入的工作表上的列中的单元格合并。 这是合并的,因为一个人可能有多个孩子,所以在这种情况下,关于父母的单元格被合并。 它不会让我复制合并的单元格。

现在我只是试图解决如何复制整个工作表,所以我知道如何复制合并的单元格,然后再执行If语句。

这是我到目前为止(大胆的底部是我试图复制合并的单元格的位置,我得到一个与ActiveSheet.Range(“**”)行错误。MergeArea.Copy

Option Explicit Sub ImportActiveList() Dim FileName As String Dim WS1 As Worksheet Dim WS2 As Worksheet Dim ActiveListWB As Workbook Set WS2 = ActiveWorkbook.Sheets("Sheet1") FileName = Application.GetOpenFilename(FileFilter:="Excel Files (*.xls*),*.xls*", _ Title:="Select Active List to Import", _ MultiSelect:=False) If FileName = "False" Then Exit Sub Else Set ActiveListWB = Workbooks.Open(FileName) End If Set WS1 = ActiveListWB.Sheets("Page1-1") WS1.UsedRange.Copy WS2.Range("A1") ActiveWorkbook.Close False End Sub Sub CalculateBirthday() Dim lastrow As Long lastrow = Range("X" & Rows.Count).End(xlUp).Row ActiveSheet.Range("A5:AA291").AutoFilter ActiveSheet.Range("$A$5:$AA$291").AutoFilter Field:=24, Criteria1:="Child" Range("AB5") = "Today's Age Year/Month" Range("AB7:AB" & lastrow).Formula = "=DATEDIF(RC[-2],TODAY(),""Y"") & "" Years, "" & DATEDIF(RC[-2],TODAY(),""YM"") & "" Months """ Columns("AB:AB").EntireColumn.AutoFit Range("AC5") = "Today's Age Year Only" Range("AC7:AC" & lastrow).Formula = "=DATEDIF(RC[-3],TODAY(),""Y"")" Columns("AC:AC").EntireColumn.AutoFit Range("AD5") = "Child 20th Birthday" Range("AD7:AD" & lastrow).Formula = "=DATE(YEAR(R[-1]C[-4])+20, MONTH(R[-1]C[-4]),DAY(R[-1]C[-4]))" Columns("AD:AD").EntireColumn.AutoFit ActiveSheet.Range("A5:AA291").MergeArea.Copy 'copies the merged cells Sheet2.Range("A1").PasteValues ' pastes what was copied into A1 on Sheet 2 and any merged cells** End Sub 

 Range("A5").Copy sheet2.Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False