Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88075

Copy and pasting only works when pasting to worksheet not cells

$
0
0

Good Morning,

I am trying to Copy and paste cell values from a master spreadsheet based on a keyword which I have placed in a separate category worksheet. I then paste the filtered information from the master worksheet into worksheets with the same name as the keyword.

I want to be able to specify which cell I paste all of the information into (the information is about 10 columns worth) but when I try to do this it doesn't work. It only works when I paste into the worksheet without any specific starting cell.

This is the code when pasting into a worksheet

Private Sub CommandButton2_Click()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Set Source = Category.Range(Category.Range("A1"), Category.Range("A1").End(xlDown))
    Set Rng = dashboard.Range("A8", dashboard.Range("N8").End(xlDown))

    For Each MyCell In Source
        If Not Evaluate("ISREF('"& CStr(MyCell) & "'!A1)") Then
            ThisWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
            ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count).Name = MyCell
        End If
    Next MyCell

    For Each MyCell In Source

        dashboard.Range("A8").AutoFilter Field:=13, Criteria1:=MyCell
        On Error Resume Next
        Rng.SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Worksheets(MyCell.Value).Paste
        dashboard.Range("A8").AutoFilter Field:=13

    Next MyCell

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub

The code above works, but it will always drop the data at Cell A1. I want to do formatting around it so need to be able to specify the cell that the information is pasted to. Any help would be greatly appreciated.

I have tried the code below to paste to a specific cell but it is not working.

Private Sub CommandButton2_Click()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Set Source = Category.Range(Category.Range("A1"), Category.Range("A1").End(xlDown))
    Set Rng = dashboard.Range("A8", dashboard.Range("N8").End(xlDown))

    For Each MyCell In Source
        If Not Evaluate("ISREF('"& CStr(MyCell) & "'!A1)") Then
            ThisWorkbook.Sheets.Add After:=Sheets(Sheets.Count)
            ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count).Name = MyCell
        End If
    Next MyCell

    For Each MyCell In Source

        dashboard.Range("A8").AutoFilter Field:=13, Criteria1:=MyCell
        On Error Resume Next
        Rng.SpecialCells(xlCellTypeVisible).Copy
        ThisWorkbook.Worksheets(MyCell.Value).Range("A1").Paste
        dashboard.Range("A8").AutoFilter Field:=13

    Next MyCell

    Application.ScreenUpdating = True
    Application.DisplayAlerts = True

End Sub

Thank you in advance.


Viewing all articles
Browse latest Browse all 88075

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>