gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
right a VBA code to copy paste a column in each sheet
- User
right a VBA code to copy paste a column in each sheet
- Assistant
Sure! Here's an example VBA code that copies and pastes a specific column in each sheet of a workbook:
Sub CopyPasteColumn() Dim ws As Worksheet Dim sourceColumn As Range, destinationColumn As Range Dim lastRow As Long ' Set the column that you want to copy and paste Set sourceColumn = ThisWorkbook.Sheets("Sheet1").Range("A:A") ' Loop through each sheet in the workbook For Each ws In ThisWorkbook.Sheets ' Check if the current sheet is the sheet you want to skip If ws.Name <> "Sheet1" Then ' Find the last row in the column of the current sheet lastRow = ws.Cells(ws.Rows.Count, sourceColumn.Column).End(xlUp).Row ' Set the destination range to paste the column data Set destinationColumn = ws.Cells(1, sourceColumn.Column).Resize(lastRow, 1) ' Copy and paste the column data on the current sheet sourceColumn.Copy destinationColumn End If Next ws End SubIn this code, the column to copy is defined as column A in "Sheet1". The code will loop through each sheet in the workbook, skipping "Sheet1", find the last row in column A of each sheet, and then copy and paste the column A data on each respective sheet.