Help with code

R

Richard

Why does it copy from Sheet1 to Sheet2 row 9 instead of
copying it to Sheet2 row 3. Anyone know of another way of
deleting unused rows because this method doesn't work.
gives run time error.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
If Target.Column = 1 Then 'CStr converts a numeric
value to a string
Application.Calculate 'Only needed if Calculation is set
to Manual
Sheet2.UsedRange.SpecialCells(xlCellTypeLastCell)(2,
1).EntireRow.Resize(1, 9) = Target.EntireRow.Resize(1,
9).Value
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim lngRow As Long
Application.EnableEvents = False
lngRow = Cells(65536, 1).End(xlUp).Row
If lngRow >= 1 Then
Worksheets("Sheet2").Range("B3").Formula = "=countif
(Sheet1!A$3:A$2000,A3)"
Worksheets("Sheet2").Range("B3:B" & lngRow).FillDown
End If
Sheets("Sheet2").Range("$A:$A").AdvancedFilter _
Action:=xlFilterInPlace, _
Unique:=True
Application.EnableEvents = True
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error GoTo inputagain
[A:A].SpecialCells(xlBlanks).EntireRow.Delete
inputagain: Exit Sub
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top