PC Review


Reply
Thread Tools Rate Thread

Copy 18 Cells in one row

 
 
AirgasRob
Guest
Posts: n/a
 
      5th Aug 2009
Greetings and thank you for taking the time to help me.

I want to be able to go across row 1 until I meet criteria >0.
Then copy 18 cells (columns) across and paste them to row 2.
For example A10 is first cell that >0
copy that cell and the next 17 cells in that row
paste in B10 across.

The sub I was using works great but only for copying columns across.

Sub LoopCol5()
Dim RngCol5 As Range
Dim i As Range
Dim c As Long
Set RngCol5 = Range("AS4", Range("AS" & Rows.Count).End(xlUp))
For Each i In RngCol5
Select Case i.Value
Case "1": c = 10
Case Else: c = -9999
End Select
If c > -9999 Then
Cells(i.Row, 8).Value = Cells(i.Row, c).Value
End If
Next i
End Sub

 
Reply With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      5th Aug 2009
Your description is somewhat confusing. You say "go across row 1....and
paste them to row 2", but then say in your example to put A1 and next 17
cells in that row into B10??? On top of that, your example code looks like
it is iterating down a column, not across a row. Can you clarify what you
are trying to do for us?

--
Rick (MVP - Excel)


"AirgasRob" <(E-Mail Removed)> wrote in message
news:72364C80-D4B0-4638-BC17-(E-Mail Removed)...
> Greetings and thank you for taking the time to help me.
>
> I want to be able to go across row 1 until I meet criteria >0.
> Then copy 18 cells (columns) across and paste them to row 2.
> For example A10 is first cell that >0
> copy that cell and the next 17 cells in that row
> paste in B10 across.
>
> The sub I was using works great but only for copying columns across.
>
> Sub LoopCol5()
> Dim RngCol5 As Range
> Dim i As Range
> Dim c As Long
> Set RngCol5 = Range("AS4", Range("AS" & Rows.Count).End(xlUp))
> For Each i In RngCol5
> Select Case i.Value
> Case "1": c = 10
> Case Else: c = -9999
> End Select
> If c > -9999 Then
> Cells(i.Row, 8).Value = Cells(i.Row, c).Value
> End If
> Next i
> End Sub
>


 
Reply With Quote
 
AirgasRob
Guest
Posts: n/a
 
      5th Aug 2009
Hi Rick,
Sorry for confusion.

I would like to start in cell A1 and go across until I find >0
A1, B1, C1, ect..

If A1 is first cell >0 then copy that cell and the next 17 cells. A1:R1

Then paste values 3 rows down in this case A4:R4
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      6th Aug 2009
Does this do what you want?

Sub MoveFirstNonZeroPlusNext17Cells()
Dim X As Long
For X = 1 To Columns.Count - 18
If Cells(1, X).Value > 0 Then
Cells(1, X).Resize(1, 18).Copy Cells(1, X).Offset(3)
Exit For
End If
Next
End Sub

--
Rick (MVP - Excel)


"AirgasRob" <(E-Mail Removed)> wrote in message
news:C23AF5C3-E887-4EA7-81FF-(E-Mail Removed)...
> Hi Rick,
> Sorry for confusion.
>
> I would like to start in cell A1 and go across until I find >0
> A1, B1, C1, ect..
>
> If A1 is first cell >0 then copy that cell and the next 17 cells. A1:R1
>
> Then paste values 3 rows down in this case A4:R4


 
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 an intial cells contents into the next series of blank cells ina column freeriderxlt Microsoft Excel Discussion 2 25th Aug 2009 07:47 AM
RE: Copy Visible Cells in Sheet with Merged and Hidden Cells FSt1 Microsoft Excel Misc 1 2nd Oct 2008 12:51 AM
macro needed to copy blocks of cells across to list of cells down =?Utf-8?B?cGllcnNvbnBybw==?= Microsoft Excel Programming 3 28th Mar 2007 12:51 PM
How to use macros to copy a range of cells which can exclude some cells which I didn't want to be copied? excelnovice Microsoft Excel Worksheet Functions 2 25th Sep 2005 12:38 AM
How to COPY from cells to cells w/o affecting respective formulae underneath ? EduardoDon Microsoft Excel New Users 1 21st Apr 2004 12:12 AM


Features
 

Advertising
 

Newsgroups
 


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