gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,341
- Office Version
- 365
- Platform
- Windows
I have this code that works great if there is data in row 3. It moves all the data as I need it to if there is data in column a in row 3 down. But if there is not data its copying row 2 which is the titles of the columns
how can I adjust this so that is there is no data from row 3 down it doesn't paste or move the data. I still want it to clear Table7\
Thanks for the Help!
Thank you!
how can I adjust this so that is there is no data from row 3 down it doesn't paste or move the data. I still want it to clear Table7\
Thanks for the Help!
Code:
Sub MoveCStoCSTable()
Sheets("CS Table").Visible = True
'***************************
'Clear Table'
'***************************
Sheets("CS Table").Select
ActiveSheet.ListObjects("Table7").HeaderRowRange.Select
'Remove the filters if one exists.
If ActiveSheet.FilterMode Then
Selection.AutoFilter
End If
'Clear all lines but the first one in the table leaving formulas for the next go round.
With Worksheets("CS Table").ListObjects("Table7")
.Range.AutoFilter
On Error Resume Next
.DataBodyRange.Offset(1).Resize(.DataBodyRange.Rows.Count - 1, .DataBodyRange.Columns.Count).Rows.Delete
If .ListColumns.Count > 1 Then
.DataBodyRange.Rows(1).SpecialCells(xlCellTypeConstants).ClearContents
Else
With .DataBodyRange.Cells(1)
If Not .HasFormula Then .ClearContents
End With
End If
End With
'************************************
'Repopulate table with cost Source
'************************************
Dim CSLR As Long
CSLR = Sheets("Cost Sources").Cells(Rows.Count, "A").End(xlUp).Row
Sheets("Cost Sources").Range("A3:" & "AE" & CSLR).Copy
Sheets("CS Table").Range("B11").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
' Application.Goto Sheet18.Range("B16")
End Sub
Thank you!