Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Copy row info but not in normal column sequence

A fairly simple macro to lookup the date posted in cell B1 and for each matching date in the named range DataA column, return data in a non sequential
manner.

As below the data returned is column 3, 1, 4 & 8. This works okay but the final version has 11 columns to return in a similar "scatter gun" method.

In this case it would be columns in this order from the DataA column C:

D, G, R, S, W, AF, AG, Y, AD, N & AE.

Making eleven different offset copy lines seems a bit clunky, but it would be the easiest for me, as I don't know how to skip various column and then return back to get them without the individual copy offsets.

Then the next hurdle is to return the data to C10 through M10 and downward from there.

Thanks,
Howard


Option Explicit

Sub DataACopy()

Dim DataA As Range
Dim c As Range
Dim aDate As String

aDate = Range("B1").Value

Application.ScreenUpdating = False
For Each c In Range("DataA")
If c.Value = aDate Then
c.Offset(, 3).Copy
Sheets("Sheet2").Range("C100").End(xlUp).Offset(1, 0).PasteSpecial

c.Offset(, 1).Copy
Sheets("Sheet2").Range("D100").End(xlUp).Offset(1, 0).PasteSpecial

c.Offset(, 4).Copy
Sheets("Sheet2").Range("E100").End(xlUp).Offset(1, 0).PasteSpecial

c.Offset(, 8).Copy
Sheets("Sheet2").Range("F100").End(xlUp).Offset(1, 0).PasteSpecial

End If
Next
Application.ScreenUpdating = True
Application.CutCopyMode = False
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy row info but not in normal column sequence

Hi Howard,

Am Wed, 12 Jun 2013 10:41:43 -0700 (PDT) schrieb Howard:

In this case it would be columns in this order from the DataA column C:

D, G, R, S, W, AF, AG, Y, AD, N & AE.

Making eleven different offset copy lines seems a bit clunky, but it would be the easiest for me, as I don't know how to skip various column and then return back to get them without the individual copy offsets.


have a try:

Sub Test()
Dim myArr As Variant
Dim rngC As Range
Dim i As Integer
Dim j As Integer
Dim LRow As Long

myArr = Array("D", "G", "R", "S", "W", "AF", _
"AG", "Y", "AD", "N", "AE")

LRow = Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Row
With Sheets("Sheet1")
For Each rngC In Range("DataA")
If rngC = .Range("B1") Then
LRow = LRow + 1
j = 3
For i = LBound(myArr) To UBound(myArr)
.Cells(rngC.Row, myArr(i)).Copy _
Sheets("Sheet2").Cells(LRow, j)
j = j + 1
Next i
End If
Next rngC
End With
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Copy row info but not in normal column sequence

have a try:



Sub Test()

Dim myArr As Variant

Dim rngC As Range

Dim i As Integer

Dim j As Integer

Dim LRow As Long



myArr = Array("D", "G", "R", "S", "W", "AF", _

"AG", "Y", "AD", "N", "AE")



LRow = Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Row

With Sheets("Sheet1")

For Each rngC In Range("DataA")

If rngC = .Range("B1") Then

LRow = LRow + 1

j = 3

For i = LBound(myArr) To UBound(myArr)

.Cells(rngC.Row, myArr(i)).Copy _

Sheets("Sheet2").Cells(LRow, j)

j = j + 1

Next i

End If

Next rngC

End With

End Sub





Regards

Claus Busch


Thanks Claus,

Looking good. Just need it to copy to row C10 on first copy and on down with subsequent copies. Goes to C2 as is.

Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy row info but not in normal column sequence

Hi Howard,

Am Wed, 12 Jun 2013 11:51:51 -0700 (PDT) schrieb Howard:

Looking good. Just need it to copy to row C10 on first copy and on down with subsequent copies. Goes to C2 as is.


if the it always should copy to C10 then you can write:
LRow = 10
But if the table will become larger then try it with MAX. And j is not
needed:

Sub Test()
Dim myArr As Variant
Dim rngC As Range
Dim i As Integer
Dim LRow As Long

myArr = Array("D", "G", "R", "S", "W", "AF", _
"AG", "Y", "AD", "N", "AE")

LRow = Sheets("Sheet2").Cells(Rows.Count, "C").End(xlUp).Row
LRow = WorksheetFunction.Max(9, LRow)
With Sheets("Sheet1")
For Each rngC In Range("DataA")
If rngC = .Range("B1") Then
LRow = LRow + 1
For i = LBound(myArr) To UBound(myArr)
.Cells(rngC.Row, myArr(i)).Copy _
Sheets("Sheet2").Cells(LRow, i + 3)
Next i
End If
Next rngC
End With
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Copy row info but not in normal column sequence


<But if the table will become larger then try it with MAX. And j is not
needed:

Exactly what I needed.

As always, thanks a ton Claus.

Regards,
Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Copy row info but not in normal column sequence

Hi Howard,

Am Wed, 12 Jun 2013 12:14:33 -0700 (PDT) schrieb Howard:

Exactly what I needed.


a liitle step to optimize the code:
You can refer directly instead of copy and paste:
For i = LBound(myArr) To UBound(myArr)
Sheets("Sheet2").Cells(LRow, i + 3) = _
.Cells(rngC.Row, myArr(i))
Next i


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Copy row info but not in normal column sequence

On Wednesday, June 12, 2013 10:47:10 PM UTC-7, Claus Busch wrote:
Hi Howard,



Am Wed, 12 Jun 2013 12:14:33 -0700 (PDT) schrieb Howard:



Exactly what I needed.




a liitle step to optimize the code:

You can refer directly instead of copy and paste:

For i = LBound(myArr) To UBound(myArr)

Sheets("Sheet2").Cells(LRow, i + 3) = _

.Cells(rngC.Row, myArr(i))

Next i





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


I'll plug that in and give it a try.

Thanks again.

Howard
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 info into blank cells within a column (going up the co Marty Excel Discussion (Misc queries) 1 January 19th 09 12:18 AM
Copy info into empty cells below info, until finds cell with new d Fat Jack Utah Excel Discussion (Misc queries) 3 November 16th 08 08:34 PM
How to update column info based on column info from another worksh Hummingbird Excel Discussion (Misc queries) 3 July 29th 08 09:54 PM
comparing a column of cell and then copy info Kelly******** Excel Programming 0 March 21st 06 11:08 PM
comparing a column of cell and then copy info to other cells Kelly******** Excel Discussion (Misc queries) 0 March 21st 06 09:51 AM


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

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"