Help! Pasting data to sheets based on names

Xineq

New Member
Joined
Aug 29, 2014
Messages
34
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

R (Sheet names)STUVW
5Overview 2014-4116917
6Overview 2015-16031221
7Overview 2014-320316

<tbody>
</tbody>


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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
try this code slip

Code:
Sheets(strDestinationSheet).cells(rows.count,"A").end(xlup).offset(1,0).PasteSpecial xlPasteValues
 
Upvote 0
Hey Venkat

when i try your code, it gives me the error message subscript is out of range. When i debug it this is what i get.

Code:
Public Function LastRowInOneColumn(sheetName As String, col As String)
    [COLOR=#ff8c00][/COLOR][COLOR=#ff8c00][/COLOR][COLOR=#ff8c00][/COLOR][COLOR=#ff8c00]LastRowInOneColumn = Sheets(sheetName).Cells(Sheets(sheetName).Rows.Count, col).End(xlUp).Row[/COLOR]
End Function

Btw thanks for the help :) and sorry for the late feedback
 
Upvote 0
Arhh thanks, it's because i some time have some blanks cells that it cant find :) do you know how to tell the code to ignor them :)

i tryed with
Code:
SkipBlanks:=True
 
Upvote 0
not clear. the named sheet is not at all available in the workbook. then question of blank cells does not arise
if there is a sheet named like that the error will not be subscript out of range.

clarify.
 
Upvote 0

Forum statistics

Threads
1,215,586
Messages
6,125,686
Members
449,249
Latest member
ExcelMA

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