PC Review


Reply
Thread Tools Rate Thread

Copy contents of cell to another tab

 
 
Beginner for Macro
Guest
Posts: n/a
 
      6th Aug 2009
I am trying to copy a contents of cell to the other tab in the same
spreadsheet and written the macro as below.

Sub AddComment()
'
' AddComment Macro
' Macro recorded
'
Selection.Copy
Sheets("Comments").Select
Selection.SpecialCells(xlCellTypeLastCell).Select
Range("A4").Select
ActiveSheet.Paste
Range("B4").Select
End Sub

What it is doing is copy the 'selected cell' in the sheet only.
As my spreasheet is very wide, I want to be able to run the macro from any
cell in a perticular row and copy a specific cell contents (e.g. contents
from column A for the selected row)

Help is much appriciated.
Thanks.
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      6th Aug 2009
I don't quite follow what you are trying to do, but maybe you can adapt this
example to your needs

Sub test()
Dim rngSource As Range
Dim rngDest As Range

Set rngSource = ActiveWorkbook.Worksheets("Sheet1").Range("A1")
Set rngDest = ActiveWorkbook.Worksheets("Sheet2").Range("B2")

rngSource.Copy Destination:=rngDest

End Sub

rngDest should be same size as rngSource or it can be a single cell

If you only want to paste values, you could use the PasteSpecial function
but you can also do this

rngDest.Value = rngSource.Value

In passing, although the macro recorder faithfully records your Select and
Activate keystrokes you seldom need to use Select or Activate in your actual
code.

Regards,
Peter T


"Beginner for Macro" <Beginner for (E-Mail Removed)> wrote in
message news:0BA37802-6FBC-4BEB-86B5-(E-Mail Removed)...
>I am trying to copy a contents of cell to the other tab in the same
> spreadsheet and written the macro as below.
>
> Sub AddComment()
> '
> ' AddComment Macro
> ' Macro recorded
> '
> Selection.Copy
> Sheets("Comments").Select
> Selection.SpecialCells(xlCellTypeLastCell).Select
> Range("A4").Select
> ActiveSheet.Paste
> Range("B4").Select
> End Sub
>
> What it is doing is copy the 'selected cell' in the sheet only.
> As my spreasheet is very wide, I want to be able to run the macro from any
> cell in a perticular row and copy a specific cell contents (e.g. contents
> from column A for the selected row)
>
> Help is much appriciated.
> Thanks.



 
Reply With Quote
 
Beginner for Macro
Guest
Posts: n/a
 
      10th Aug 2009
Sorry, I should have explained a lil bit more.

What I have is a database very wide and long.
The range for the code example below looks like this
Column A : Header A1 = Country, A2:A? = Country names
Column B : Header B1 = Name, B2:B? = Names
Column C : Header C1 = Gender, C2:C? = F or M
Column D : Header D1 = Birthday, D2? = Dates
Column ...: ......
Column XXX : Header XXX1 = Last Update, XXX2:XYZ? = Dates

I want to be able to run a macro while on XXXn (or any other cell in that
row) but copy the contents from Bn (contents in column B for the same row,
i.e. B2 if the selection is anywhere in row 2 and B5 if the selection is
anywhere in row 5) to anoother Tab in the same spreadheet.

The problem I am having with the macro written above (in the original
posting) is it copys the contents from XXXn (whatever the other cell selected
before running that macro) and not from column 'B'.

I hope this is useful and a bit more clear.
Thanks in advance.


"Peter T" wrote:

> I don't quite follow what you are trying to do, but maybe you can adapt this
> example to your needs
>
> Sub test()
> Dim rngSource As Range
> Dim rngDest As Range
>
> Set rngSource = ActiveWorkbook.Worksheets("Sheet1").Range("A1")
> Set rngDest = ActiveWorkbook.Worksheets("Sheet2").Range("B2")
>
> rngSource.Copy Destination:=rngDest
>
> End Sub
>
> rngDest should be same size as rngSource or it can be a single cell
>
> If you only want to paste values, you could use the PasteSpecial function
> but you can also do this
>
> rngDest.Value = rngSource.Value
>
> In passing, although the macro recorder faithfully records your Select and
> Activate keystrokes you seldom need to use Select or Activate in your actual
> code.
>
> Regards,
> Peter T
>
>
> "Beginner for Macro" <Beginner for (E-Mail Removed)> wrote in
> message news:0BA37802-6FBC-4BEB-86B5-(E-Mail Removed)...
> >I am trying to copy a contents of cell to the other tab in the same
> > spreadsheet and written the macro as below.
> >
> > Sub AddComment()
> > '
> > ' AddComment Macro
> > ' Macro recorded
> > '
> > Selection.Copy
> > Sheets("Comments").Select
> > Selection.SpecialCells(xlCellTypeLastCell).Select
> > Range("A4").Select
> > ActiveSheet.Paste
> > Range("B4").Select
> > End Sub
> >
> > What it is doing is copy the 'selected cell' in the sheet only.
> > As my spreasheet is very wide, I want to be able to run the macro from any
> > cell in a perticular row and copy a specific cell contents (e.g. contents
> > from column A for the selected row)
> >
> > Help is much appriciated.
> > Thanks.

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy cell contents, then paste into the same cell with other text. bluenote31 Microsoft Excel Misc 6 9th Feb 2010 09:18 PM
How can I automatically copy cell contents from one cell into anot geeeberry Microsoft Excel New Users 2 6th Jul 2008 10:33 AM
Copy contents to cell based on value in second cell =?Utf-8?B?TWlrZSBDYXJwZW50ZXI=?= Microsoft Excel Misc 3 21st Apr 2006 03:01 PM
Data entry - Copy contents of cell typed in one cell to another ce =?Utf-8?B?ZGFuaWU=?= Microsoft Excel Worksheet Functions 2 16th Mar 2006 06:51 PM
want to copy the contents of a cell into another place based on the contents of a cel CBlev Microsoft Excel Misc 0 9th Sep 2003 10:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:02 AM.