Help - Search - Members - Calendar
Full Version: Vb Help
BleepingComputer.com > Software > Programming
   
Aggie1995
I am new to VB and am running into trouble when trying to record a macro in Excel.

I would like to copy a column from one sheet and run the macro in multiple sheets to have it paste this information. I recorded a simple macro to illustrate:

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 4/28/2008 by PREWITRO
'

'
Sheets("Sheet1").Select
Columns("A:A").Select
Selection.Copy
Sheets("Sheet2").Select
Columns("A:A").Select
ActiveSheet.Paste
End Sub


The problem is, when I now go to sheet 3 and run this macro, it copies the data from sheet1 and then jumps to sheet2. The data is never pasted into sheet 3.

Is there any way to write code to pick the sheet that you started running the macro from?

Any suggestions would be appreciated.

Thanks...
adh_amit
try the following:

Sub Macro1()
'
ActiveWorkbook.Worksheets("Sheet1").Columns("A:A").Copy Destination:=ActiveWorkbook.Worksheets("sheet2").Columns("A:A")

End Sub

This will paste data from column A from sheet 1 to column A of sheet 2

If you want to copy paste same column A from Sheet 1 to mulitple sheets, you can put this statment in loop.But then, you will have to save the name of the new sheet in some variable and substitute it to sheet 2 in my example.

This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.