Hey Mr. Excel
I have this Code seen below. The point of the macro is to past data from my source sheet to sheets with matching names with some cell values.
I have the following sheet setup
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]R (Sheet names)[/TD]
[TD]S[/TD]
[TD]T[/TD]
[TD]U[/TD]
[TD]V[/TD]
[TD]W[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Overview 2014-4[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]6[/TD]
[TD]9[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Overview 2015-1[/TD]
[TD]6[/TD]
[TD]0[/TD]
[TD]3[/TD]
[TD]12[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Overview 2014-3[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD]3[/TD]
[TD]1[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
More specific info:
In my source sheet named "Counting" i have sheet names in column R and i want to split the data onto all the sheets that matchs with the cell name of the sheets. So I want to copy columns S to the end onto columns A(lastrow) on the destination.
This is my Code i trying to do it with: I just get a problem in the last line, getting the error "Application-defined or object-defined error" "Run time error 1004"
(When i debug)
Hope you can help me
I have this Code seen below. The point of the macro is to past data from my source sheet to sheets with matching names with some cell values.
I have the following sheet setup
[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]R (Sheet names)[/TD]
[TD]S[/TD]
[TD]T[/TD]
[TD]U[/TD]
[TD]V[/TD]
[TD]W[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Overview 2014-4[/TD]
[TD]1[/TD]
[TD]1[/TD]
[TD]6[/TD]
[TD]9[/TD]
[TD]17[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]Overview 2015-1[/TD]
[TD]6[/TD]
[TD]0[/TD]
[TD]3[/TD]
[TD]12[/TD]
[TD]21[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Overview 2014-3[/TD]
[TD]2[/TD]
[TD]0[/TD]
[TD]3[/TD]
[TD]1[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
More specific info:
In my source sheet named "Counting" i have sheet names in column R and i want to split the data onto all the sheets that matchs with the cell name of the sheets. So I want to copy columns S to the end onto columns A(lastrow) on the destination.
This is my Code i trying to do it with: I just get a problem in the last line, getting the error "Application-defined or object-defined error" "Run time error 1004"
Code:
[COLOR=#ffd700]Sheets(strDestinationSheet).Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, 1)).PasteSpecial xlPasteValues[/COLOR]
Code:
Sub copyPasteData()
Dim strSourceSheet As String
Dim strDestinationSheet As String
Dim lastRow As Long
Dim lastSourceRow As Long
Dim currRow As Long
strSourceSheet = "Counting"
Sheets(strSourceSheet).Visible = True
Sheets(strSourceSheet).Select
lastSourceRow = LastRowInOneColumn(strSourceSheet, "R")
For currRow = 5 To lastSourceRow
strDestinationSheet = Cells(currRow, 18)
Range(Cells(currRow, 19), Cells(currRow, Cells(currRow, 19).CurrentRegion.Columns.Count)).Copy
lastRow = LastRowInOneColumn(strDestinationSheet, "A")
[COLOR=#ffd700]Sheets(strDestinationSheet).Range(Cells(lastRow + 1, 1), Cells(lastRow + 1, 1)).PasteSpecial xlPasteValues[/COLOR]
Next
End Sub
Public Function LastRowInOneColumn(sheetName As String, col As String)
LastRowInOneColumn = Sheets(sheetName).Cells(Sheets(sheetName).Rows.Count, col).End(xlUp).Row
End Function
(When i debug)
Hope you can help me