Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
mp mp is offline
external usenet poster
 
Posts: 70
Default better way to copy cells

I hacked this together based on recording a macro and revising
is there a better way?

'copy formulas in G, H, and I down one row
Sub CopyGHIDownOne(rowNumber As Long)

Range("G" & CStr(rowNumber) & ":I" & CStr(rowNumber)).Select
Selection.Copy
Range("G" & CStr(rowNumber + 1) & ":I" & CStr(rowNumber + 1)).Select
ActiveSheet.Paste

End Sub

thanks
mark


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default better way to copy cells

mp pretended :
I hacked this together based on recording a macro and revising
is there a better way?

'copy formulas in G, H, and I down one row
Sub CopyGHIDownOne(rowNumber As Long)

Range("G" & CStr(rowNumber) & ":I" & CStr(rowNumber)).Select
Selection.Copy
Range("G" & CStr(rowNumber + 1) & ":I" & CStr(rowNumber + 1)).Select
ActiveSheet.Paste

End Sub

thanks
mark


Try this single line of code...

Range("G" &CStr(rowNumber).Resize(1, 3).Copy Range("G" & CSTR(rowNumber
+ 1))

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default better way to copy cells

Try this single line of code...

Range("G" &CStr(rowNumber).Resize(1, 3).Copy Range("G" &
CSTR(rowNumber + 1))


How about this much shorter one-liner....

Cells(rowNumber, "G").Resize(2, 3).FillDown

and, if you don't mind using column numbers instead of letters, this even
shorter one still...

Cells(rowNumber, 7).Resize(2, 3).FillDown

Rick Rothstein (MVP - Excel)

  #4   Report Post  
Posted to microsoft.public.excel.programming
mp mp is offline
external usenet poster
 
Posts: 70
Default better way to copy cells


"Rick Rothstein" wrote in message
...
Try this single line of code...

Range("G" &CStr(rowNumber).Resize(1, 3).Copy Range("G" &
CSTR(rowNumber + 1))


How about this much shorter one-liner....

Cells(rowNumber, "G").Resize(2, 3).FillDown

and, if you don't mind using column numbers instead of letters, this even
shorter one still...

Cells(rowNumber, 7).Resize(2, 3).FillDown

Rick Rothstein (MVP - Excel)


Thanks Rick
I appreciate your help.
Mark


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default better way to copy cells

Rick Rothstein was thinking very hard :
Try this single line of code...

Range("G" &CStr(rowNumber).Resize(1, 3).Copy Range("G" &
CSTR(rowNumber + 1))


How about this much shorter one-liner....

Cells(rowNumber, "G").Resize(2, 3).FillDown

and, if you don't mind using column numbers instead of letters, this even
shorter one still...

Cells(rowNumber, 7).Resize(2, 3).FillDown

Rick Rothstein (MVP - Excel)


Still shining!<g

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default better way to copy cells

Rick Rothstein submitted this idea :
Try this single line of code...

Range("G" &CStr(rowNumber).Resize(1, 3).Copy Range("G" &
CSTR(rowNumber + 1))


How about this much shorter one-liner....

Cells(rowNumber, "G").Resize(2, 3).FillDown

and, if you don't mind using column numbers instead of letters, this even
shorter one still...

Cells(rowNumber, 7).Resize(2, 3).FillDown

Rick Rothstein (MVP - Excel)


Not trying to dim your shine (which is not possible to do<g), Rick,
but it just occured to me that your solution will only work if the
cells are contiguous. Mine will work whether they're contiguous or not
contiguous!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default better way to copy cells

but it just occured to me that your solution will only work if the cells
are contiguous. Mine will work whether they're contiguous or not
contiguous!


Can you show me the VB statement you have in mind for your non-contiguous
case?

Rick Rothstein (MVP - Excel)

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default better way to copy cells

Rick Rothstein formulated on Saturday :
but it just occured to me that your solution will only work if the cells
are contiguous. Mine will work whether they're contiguous or not
contiguous!


Can you show me the VB statement you have in mind for your non-contiguous
case?

Rick Rothstein (MVP - Excel)


Yes. In my 1st reply it's the line that uses the destination arg of the
Copy method. Though, in this case, the destination address is
hard-coded. Under normal usage this would not be the case as it would
be retrieved during runtime via some means or another.

So then, the line could be written something like:

rngSource.Copy rngTarget

...which could be anywhere on any sheet in any open workbook.

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


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 can I copy big ranges of cells without drag or copy/paste? Ricardo Julio Excel Discussion (Misc queries) 3 March 23rd 10 02:38 PM
Copy and paste versus copy and insert copied cells Alana New Users to Excel 1 September 28th 07 08:58 PM
How can I copy the values of all selected cells to the same cells inanother Sheet [email protected] Excel Programming 2 August 8th 06 05:45 PM
Copy/Paste how to avoid the copy of formula cells w/o calc values Dennis Excel Discussion (Misc queries) 10 March 2nd 06 10:47 PM
Copy data into cells until changes trigger new copy mdeanda Excel Programming 2 April 25th 05 01:32 PM


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

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

About Us

"It's about Microsoft Excel"