Forum Discussion

JDexcelNEW's avatar
JDexcelNEW
Copper Contributor
Jan 10, 2025

Multiple unique cells copied to separate workbook

Hello,

I am trying to create a macro or button that will take data or text from multiple cells (example C4,E6,G6) and copy that data to another workbook, this would not be so difficult normally however the data needs to be copied to certain areas and biased on the date (which will be in the first worksheet C5). for example C4 needs to be copied to workbook "Data arc" in the first available row in column "A" and worksheet "Jan" if the date is 1/xx/2025 or in worksheet "Feb" if the date is 2/xx/2025. E6 would need to be copied to first available row in column "M" with the same date criteria. this is a small example of what i need but if anyone can show me how to do this i should be able to figure the rest out.

  • See if you can use this as starting point.

    Sub Test()
        Dim wsS As Worksheet
        Dim wbT As Workbook
        Dim wsT As Worksheet
        Dim stM As String
        Set wsS = ActiveSheet
        Set wbT = Workbooks("Data arc.xlsx") ' or Workbooks.Open("...\Data arc.xlsx")
        stM = Format(wsS.Range("C5").Value, "mmm")
        Set wsT = wbT.Worksheets(stM)
        wsT.Range("A" & wsT.Rows.Count).End(xlUp).Offset(1).Value = wsS.Range("C4").Value
        wsT.Range("M" & wsT.Rows.Count).End(xlUp).Offset(1).Value = wsS.Range("E6").Value
        ' etc.
    End Sub

     

    • JDexcelNEW's avatar
      JDexcelNEW
      Copper Contributor

      Thank you, I think i can get it to work with this.

Resources