0
votes

I am trying to loop through column A (Cell A3 to A5) of worksheet, Sheet1 (cell values are 1, 2 ,and 3). And copy and paste the values into other worksheets in cell A1. So Sheet2 A1 has 1 , Sheet3 A1 has 2 and Sheet4 A1 has 3 . Instead my code ends up putting 3 into all the worksheets. Can anyone help? Thanks in advance

Sub test()
    Dim X As Long, Y As Long

    For X = 2 To Worksheets.Count        
        For Y = 3 To 5
            Sheets("sheet1").Range("A" & Y).Copy Worksheets(X).Range("A1")

End Sub
2
Note that both of your For loops are missing a Next.Pᴇʜ

2 Answers

0
votes

This should work:

Option Explicit

Sub RunIT()
  Dim rng As Range

  Dim intI As Integer

  Set rng = Worksheets(1).Range("A3:A5")

  For intI = 2 To Worksheets.Count
      rng.Cells(intI - 1, 1).Copy Worksheets(intI).Range("A1")
  Next intI

  Set rng = Nothing

End Sub
0
votes

Copy to Worksheets

Visualize

enter image description here

The Code

Sub CopyToWorksheets()

    ' List of Worksheet Names
    Const cSheets As String = "Sheet1,Sheet2,Sheet3,Sheet4"
    Const cRange As String = "A3:A5"  ' Source Worksheet Range
    Const cCell As String = "A1"      ' Target Worksheet Cell Range

    Dim vntWs As Variant  ' Worksheet Array
    Dim i As Long         ' Worksheet Array Row Counter

    ' Split List of Worksheet Names into Worksheet Array.
    vntWs = Split(cSheets, ",")

    ' In Source Worksheet
    With ThisWorkbook.Worksheets(vntWs(0))
        ' Loop through cells of Source Worksheet Range.
        For i = 1 To UBound(vntWs)
            ' Copy value of current cell of Source Worksheet Range
            ' to current Target Worksheet Cell Range.
            .Parent.Worksheets(vntWs(i)).Range(cCell) = .Range(cRange).Cells(i)
        Next
    End With

End Sub