hi, I have the VBA code which copies from worksheet to another. Rows are also inserted in sh2 where sh1 has greater than 15 rows beginning row 7. Row 6 has a formula in columns E and I and I would like to be able to copy the formula into rows that were inserted by the macro. How can I add this function into the macro below? Unfortunately I do not understand some of the threads I've come across on this topic.
Sub t()
Dim wb As Workbook, sh1 As Worksheet, sh2 As Worksheet, lr As Long, fName As String, cell As Range
fName = Application.GetOpenFilename("Excel Files(*.xls*), *.xls*")
Set sh2 = ActiveSheet
Set wb = Workbooks.Open(fName)
Set sh1 = wb.Sheets(1)
lr = sh1.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
With sh1
.UsedRange.AutoFilter 2, "<>" & "PAYMENT"
cnt = .UsedRange.Resize(, 1).SpecialCells(xlCellTypeVisible).Count - lr + 7
If cnt <= 15 Then
.Range("B9:B" & lr).Copy
sh2.Cells(7, 1).PasteSpecial xlPasteValues
.Range("C9:C" & lr).Copy
sh2.Cells(7, 2).PasteSpecial xlPasteValues
.Range("D9:D" & lr).Copy
sh2.Cells(7, 7).PasteSpecial xlPasteValues
.AutoFilterMode = False
Else
sh2.Rows(7).Resize(cnt - 15).EntireRow.Insert
.Range("B9:B" & lr).Copy
sh2.Cells(7, 1).PasteSpecial xlPasteValues
.Range("C9:C" & lr).Copy
sh2.Cells(7, 2).PasteSpecial xlPasteValues
.Range("D9:D" & lr).Copy
sh2.Cells(7, 7).PasteSpecial xlPasteValues
.AutoFilterMode = False
End If
End With
wb.Close False
Sub t()
Dim wb As Workbook, sh1 As Worksheet, sh2 As Worksheet, lr As Long, fName As String, cell As Range
fName = Application.GetOpenFilename("Excel Files(*.xls*), *.xls*")
Set sh2 = ActiveSheet
Set wb = Workbooks.Open(fName)
Set sh1 = wb.Sheets(1)
lr = sh1.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
With sh1
.UsedRange.AutoFilter 2, "<>" & "PAYMENT"
cnt = .UsedRange.Resize(, 1).SpecialCells(xlCellTypeVisible).Count - lr + 7
If cnt <= 15 Then
.Range("B9:B" & lr).Copy
sh2.Cells(7, 1).PasteSpecial xlPasteValues
.Range("C9:C" & lr).Copy
sh2.Cells(7, 2).PasteSpecial xlPasteValues
.Range("D9:D" & lr).Copy
sh2.Cells(7, 7).PasteSpecial xlPasteValues
.AutoFilterMode = False
Else
sh2.Rows(7).Resize(cnt - 15).EntireRow.Insert
.Range("B9:B" & lr).Copy
sh2.Cells(7, 1).PasteSpecial xlPasteValues
.Range("C9:C" & lr).Copy
sh2.Cells(7, 2).PasteSpecial xlPasteValues
.Range("D9:D" & lr).Copy
sh2.Cells(7, 7).PasteSpecial xlPasteValues
.AutoFilterMode = False
End If
End With
wb.Close False