Running a macro in a selected cell...

G

Guest

This is probably a simple question, but I can't seem to figure it out...

I want to run a task of pasting several rows and columns of information into
a cell that is selected by the user.

I recorded a Macro and asigned it to a rectangular button that will copy the
information, but how can I make it paste the information starting in the
selected cell?

Thanks in advance.
 
D

Dave Peterson

dim RngToCopy as range

Set rngtocopy = worksheets("sheet99").range("a1:b99") 'or something

rngtocopy.copy _
destination:=activecell

=========
You could even ask where it should be pasted:

dim RngToCopy as range
Dim DestCell as range

set destcell = nothing
on error resume next
set destcell = application.inputbox(prompt:="select a cell",type:=8).cells(1)
on error goto 0

if destcell is nothing then
exit sub 'user hit cancel
end if

Set rngtocopy = worksheets("sheet99").range("a1:b99") 'or something

rngtocopy.copy _
destination:=destcell
 
G

Guest

Thank you Dave.

Dave Peterson said:
dim RngToCopy as range

Set rngtocopy = worksheets("sheet99").range("a1:b99") 'or something

rngtocopy.copy _
destination:=activecell

=========
You could even ask where it should be pasted:

dim RngToCopy as range
Dim DestCell as range

set destcell = nothing
on error resume next
set destcell = application.inputbox(prompt:="select a cell",type:=8).cells(1)
on error goto 0

if destcell is nothing then
exit sub 'user hit cancel
end if

Set rngtocopy = worksheets("sheet99").range("a1:b99") 'or something

rngtocopy.copy _
destination:=destcell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top