Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Vb Help


  • Please log in to reply
1 reply to this topic

#1 Aggie1995

Aggie1995

  • Members
  • 34 posts
  • OFFLINE
  •  
  • Local time:09:48 PM

Posted 28 April 2008 - 03:10 PM

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...

BC AdBot (Login to Remove)

 


#2 adh_amit

adh_amit

  • Members
  • 20 posts
  • OFFLINE
  •  
  • Local time:08:18 AM

Posted 12 May 2008 - 01:41 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users