copying to a specific sheet

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,352
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have a spreadsheet that copies entries to other sheets depending on the date. It copies perfectly to every sheet. There are sheets ranging from July 2018-June 2019. I have an entry for every month between the two dates. The only thing wrong with the copy is in the august 2018 sheet, it won't copy columns M-O from tblCosting on the home sheet to columns K-M of august 2018 sheet. There is data in every row of every cell of tblCosting. This doesn't make sense to me as the code is not monthly specific so I have no idea how to debug it.



The code I run is:

Code:
Sub cmdCopyo()
Dim wsDst As Worksheet
Dim wsSrc As Worksheet
Dim tblrow As ListRow
Dim Combo As String
Dim sht As Worksheet
Dim tbl As ListObject

    Application.ScreenUpdating = False
    
    'assign values to variables
    Set sht = Worksheets("Home")

    With sht

        Set tbl = .ListObjects("tblCosting")
        
        
        
        For Each tblrow In tbl.ListRows
            Combo = Format(tblrow.Range.Cells(1, 1), "mmmm yyyy")
            Set wsDst = Sheets(Combo)
            
            With wsDst
                'This copies the first 10 columns, i.e. A:J, of the current row of the table to column A in the destination sheet.
                tblrow.Range.Resize(, 10).copy
                .Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
                'This should go to the 15th column in the current row, i.e. column O, and copy that column and the next 2 columns, i.e. O:Q, to column K on the destination sheet.
                tblrow.Range.Offset(, 14).Resize(, 3).copy
                .Range("K" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
                'Similarly this should copy columns AD:AF from the table to column N on the destination sheet.
                tblrow.Range.Offset(, 29).Resize(, 3).copy
                .Range("N" & Rows.Count).End(xlUp).Offset(1).PasteSpecial xlPasteValuesAndNumberFormats
            End With
            
        Next tblrow
        
        Call SortDates
        
    End With
    
    Application.CutCopyMode = False

    Application.ScreenUpdating = True
    
End Sub

and......

Code:
Sub SortDates()
'
' sortDates Macro
Worksheets("home").Unprotect Password:="costings"
  'Set up your variables and turn off screen updating.
   Dim iCounter As Integer
   Dim Combo As String
        Combo = Worksheets("Home").Range("Y5")
   Application.ScreenUpdating = False
   
  
   'Sort the rows based on the data in column C

'   Sheets(Combo).Sort Key1:=Range("A4"), _
      Order1:=xlAscending, Header:=xlYes
   
   'Clear out the temporary sorting value in column C, and turn screen updating back on.
   'Columns(3).ClearContents
   Application.ScreenUpdating = True
'Worksheets("home").Protect Password:="costings"
End Sub


Can someone help me please?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Check...
1. That the august sheet is not protected
2. that august date in the table is the correct format / syntax
3. check that the copy paste is not going to another location on the august sheet......somewhere way down the page !!
4. step through the code using F8 to make sure it is actually copying the august data
 
Upvote 0
But how could most of those options be an issue if it is copying some of the cells to the august 2018 sheet?
 
Upvote 0
Steps 3 and 4 could still very well apply....!!
 
Upvote 0
Always pays to try the options suggested....(y)
 
Upvote 0

Forum statistics

Threads
1,214,545
Messages
6,120,132
Members
448,947
Latest member
test111

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top