Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Copy contents of cell to another tab

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Copy contents of cell to another tab

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 wrote in
message ...
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Copy contents of cell to another tab

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:D? = 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 wrote in
message ...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to copy the contents into another cell? sumesh56 Excel Worksheet Functions 3 March 11th 12 04:32 AM
Copy cell contents with VB TheMilkGuy Excel Discussion (Misc queries) 6 July 21st 09 11:46 PM
how to copy the contents from last cell Lamb Chop Excel Discussion (Misc queries) 2 January 17th 08 01:27 AM
Copy cell contents? NickHK Excel Programming 0 January 11th 07 02:46 AM
copy cell value not contents D Moran Excel Discussion (Misc queries) 2 April 24th 06 03:29 PM


All times are GMT +1. The time now is 06:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"