Worksheets("X").Cells(row, column) not copying values from multiple sheets

 In VBA (Visual Basic for Applications), when you use `Worksheets("X").Cells(row, column)` to copy values from multiple sheets, you need to specify the source sheets and iterate through them to copy the values. Here's an example of how you can do this:


```vba

Sub CopyValuesFromMultipleSheets()

    Dim sourceSheetNames As Variant

    Dim destSheet As Worksheet

    Dim sourceSheet As Worksheet

    Dim row As Long

    Dim column As Long


    ' Define the destination sheet where you want to paste the values

    Set destSheet = ThisWorkbook.Sheets("DestinationSheet")


    ' List the names of the source sheets in an array

    sourceSheetNames = Array("Sheet1", "Sheet2", "Sheet3")


    ' Loop through the source sheet names

    For Each sheetName In sourceSheetNames

        ' Set the source sheet

        Set sourceSheet = ThisWorkbook.Sheets(sheetName)


        ' Loop through rows and columns to copy values

        For row = 1 To sourceSheet.UsedRange.Rows.Count

            For column = 1 To sourceSheet.UsedRange.Columns.Count

                ' Copy the value from the source sheet to the destination sheet

                destSheet.Cells(row, column).Value = sourceSheet.Cells(row, column).Value

            Next column

        Next row

    Next sheetName

End Sub

```


In this example:


1. Replace `"DestinationSheet"` with the name of the sheet where you want to paste the values.


2. Add the names of the source sheets to the `sourceSheetNames` array.


3. The code iterates through the source sheet names and copies values from each source sheet to the destination sheet, row by row and column by column.


Make sure to adjust the code to match your specific sheet names, ranges, and destination sheet as needed.

Comments

Popular posts from this blog

bad character U+002D '-' in my helm template

GitLab pipeline stopped working with invalid yaml error

How do I add a printer in OpenSUSE which is being shared by a CUPS print server?