• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy Paste from one sheet to another sheet with different constraints

Nidhi210

New Member
I have two sheet.One contains Pivot table which has category name with different zone(North,East,West,South,CSD) and values in these zones category specific month wise.I need to copy this sheet with specific category to another sheet which has different sheets of category.Now I want code which can copy category from the Pivot sheet and paste value in sheet which has different sheet named based on category.Also it should be zone specific as not every time the category contains each and every zone value,month wise.the category name should be identified based on the name in the destination sheet ,Any help will be highly appreciated.
 

Attachments

  • Sample file VBA Code.xlsx
    12.4 KB · Views: 6
Should work on your workbook provided.
Code:
Sub test()
    Dim r As Range, ws As String, c As Range
    Dim x As Range, i As Long, t As Long
    With Sheets("pivot").[c3].CurrentRegion
        With .Offset(1).Resize(.Rows.Count - 1)
            For Each r In .Columns(1).SpecialCells(4).Areas
                ws = r(0).Value
                For Each c In r(0, 2).Resize(r.Count + 1)
                    Set x = Sheets(ws).Cells.Find(c)
                    If Not x Is Nothing Then
                        t = 2
                        For i = 3 To .Columns.Count Step 3
                            x(, t).Resize(, 3).Value = _
                            c(, i - 1).Resize(, 3).Value: t = t + 4
                        Next
                    End If
                Next
            Next
        End With
    End With
End Sub
 
Showing error in this command:
Set x = Sheets(ws).Cells.Find(c).No able to identify the the name of the workbook when I am specifying the name of the workbook
 
One possibility I can think of is you have Numeric sheet name.
Try change
Code:
ws = r(0).Value
to
Code:
ws = CStr(r(0).Value)
othereise, I need to see your workbook.
 

Attachments

  • Sample file VBA Code with code.xlsm
    23.2 KB · Views: 0
Should work on your workbook provided.
Code:
Sub test()
    Dim r As Range, ws As String, c As Range
    Dim x As Range, i As Long, t As Long
    With Sheets("pivot").[c3].CurrentRegion
        With .Offset(1).Resize(.Rows.Count - 1)
            For Each r In .Columns(1).SpecialCells(4).Areas
                ws = r(0).Value
                For Each c In r(0, 2).Resize(r.Count + 1)
                    Set x = Sheets(ws).Cells.Find(c)
                    If Not x Is Nothing Then
                        t = 2
                        For i = 3 To .Columns.Count Step 3
                            x(, t).Resize(, 3).Value = _
                            c(, i - 1).Resize(, 3).Value: t = t + 4
                        Next
                    End If
                Next
            Next
        End With
    End With
End Sub


Hi;
I did tested it with excel 2013.
iT WORKS FINE
 
Hi I have Uploaded my working replica sheet with many more sheets in DRM Draft FInal excel.Can u suggest the amendment to be done in the vba code
 

Attachments

  • Final Consolidated Secondary Forecast_June-Dec\'16_v2_10th May.xlsb
    27.5 KB · Views: 4
  • DRM Draft Final.xlsx
    36.4 KB · Views: 2
So the sheets I have attached as final consolidated file has the data in this, which needs to transferred to DRM Draft final in the format in the file.
 
How and where exactly to?

I don't think I can help you more, so please wait for someone else to comes in to help you.
 
Back
Top