Posts

Showing posts with the label VBA

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 =