Excel Simple macro help..... :: MrExcel Message Board


 FAQFAQ
   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   FavoritesFavorites   StatisticsStatistics 
 RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Online StoreOnline Store

MrExcel Message Board Forum Index -> Excel Questions

Simple macro help.....
Post new topic   Reply to topic
Last Thread | Next Thread  >   Printable version
  Author    Thread

ExcelNovice
Board Master


Joined: 13 May 2002
Posts: 156


Status: Offline

 Reply with quote  

I included the matter below for someone's assistance. Everything on the macro works well, except that when I run the macro, the content of cells A6:L9 is copied to cell A18. How can I change the macro so that it copies to the cell selected by the user(whatever cell that is)?
See macro below.......

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/30/02 by ExcelNovice'

'
Range("A6:L9").Select
Selection.Copy
Range("A18").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A10:A13").Select
End Sub

Post Tue Jul 30, 2002 4:18 pm 
 View user's profile Send private message

Juan Pablo González
MrExcel MVP


Joined: 09 Feb 2002
Posts: 8388
Location: Marion, IL
Flag: Colombia

Status: Offline

 Reply with quote  


quote:

On 2002-07-30 12:18, ExcelNovice wrote:
I included the matter below for someone's assistance. Everything on the macro works well, except that when I run the macro, the content of cells A6:L9 is copied to cell A18. How can I change the macro so that it copies to the cell selected by the user(whatever cell that is)?
See macro below.......

Sub Macro1()
'
' Macro1 Macro
' Macro recorded 7/30/02 by ExcelNovice'

'
Range("A6:L9").Select
Selection.Copy
Range("A18").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("A10:A13").Select
End Sub



Try with

Sub Macro1()

'
' Macro1 Macro
' Macro recorded 7/30/02 by ExcelNovice'

'
Range("A6:L9").Copy ActiveCell
Range("A10:A13").Select
End Sub


_________________
Regards,

Juan Pablo González
MrExcel.com Consulting

Read the Articles List and check out our Recommended links and Add-Ins

Post Tue Jul 30, 2002 4:21 pm 
 View user's profile Send private message Visit poster's website

Mudface
MrExcel MVP


Joined: 19 Feb 2002
Posts: 3103
Location: Sunny, spring-like Hull
Flag: England

Status: Offline

 Reply with quote  

Something like this might work OK for you, it'll paste to the active cell. I've included a quick check that the data to be pasted doesn't get overwritten:-

If Application.Intersect(Range("A6:L9"), ActiveCell) Is Nothing Then
Range("A6:L9").Copy Destination:=ActiveCell
Else
MsgBox "Please pick another cell"
End If

Post Tue Jul 30, 2002 4:24 pm 
 View user's profile Send private message

ExcelNovice
Board Master


Joined: 13 May 2002
Posts: 156


Status: Offline

 Reply with quote  

Thanks Mudface, thanks for your help. The macro works except that as soon as a cell is selected the macro runs! I need to have it so that the macro runs only when the user enables it (that is, click the macro button).

Can this be done?

Post Tue Jul 30, 2002 4:57 pm 
 View user's profile Send private message

Mudface
MrExcel MVP


Joined: 19 Feb 2002
Posts: 3103
Location: Sunny, spring-like Hull
Flag: England

Status: Offline

 Reply with quote  

Yes, I'm guessing you have put the code into the worksheet Selection_Change event. Cut out the code in between the sub declaration and the 'End Sub' and delete the rest. Then, click on Insert-Module, then Insert- Procedure. Give your Procedure an appropriate name and paste in the code. Then just run it from the macro toolbar.

Post Tue Jul 30, 2002 5:01 pm 
 View user's profile Send private message

ExcelNovice
Board Master


Joined: 13 May 2002
Posts: 156


Status: Offline

 Reply with quote  

Hi Juan Pablo G., your macro works well, but although it does what it is suppose to do, I keep getting this message:

"Cannot change part of a merged cell"

How can I stop this from happening?

Thanks.

Post Tue Jul 30, 2002 5:04 pm 
 View user's profile Send private message

ExcelNovice
Board Master


Joined: 13 May 2002
Posts: 156


Status: Offline

 Reply with quote  

Works like a charm mudface!! Really appreciate it!!

Post Tue Jul 30, 2002 5:13 pm 
 View user's profile Send private message
  Display posts from previous:      

MrExcel Message Board Forum Index -> Excel Questions


Forum Jump:
Jump to:  

Post new topic   Reply to topic
Page 1 of 1



Add To Favorites

 


Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB: 2.0.4 © 2001 phpBB Group

Need help posting your first question? Read how to post

Need extra help ? Couldn't get the answer you needed ? Get a free quote from our Consulting Team

Download Colo's HTML Maker utility for displaying your Excel Worksheet on the board.

Download VB HTML Maker to post your code on the board


Check out our new index to 485 Excel Articles.


Return to MrExcel Consulting

All contents Copyright 1998-2004 by MrExcel.com
If you believe information posted here is from your copyrighted source, notify us per the Terms of Use
Excel is a registered trademark of the Microsoft Corporation.
MrExcel is a registered trademark of Tickling Keys, Inc.