View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] jmsla...@gmail.com is offline
external usenet poster
 
Posts: 9
Default Select identical column/rows based on the active cell and copydata to another sheet

I thought....... easy to change so it can fullfill my wished result :(
So I extended the code with the other columns that I need to copy, but....... in another different way.

------ changed code -------------------
Sub FindAndCopy()
Dim rngBig As Range, c As Range
Dim FirstAddress As String

With Sheets("Sheet1")
Set c = .Columns("D").Find(what:=.Range("D" & ActiveCell.Row), _
lookat:=xlWhole)

If Not c Is Nothing Then
FirstAddress = c.Address
Do

If rngBig Is Nothing Then
Set rngBig = Union(c, .Range("F" & c.Row & ":G" & c.Row), .Range("H" & c.Row), _
.Range("M" & c.Row), .Range("S" & c.Row), .Range("U" & c.Row), .Range("X" & c.Row), _
.Range("AA" & c.Row), .Range("AD" & c.Row), .Range("AG" & c.Row), .Range("AJ" & c.Row), .Range("AM" & c.Row), _
.Range("AB" & c.Row), .Range("AE" & c.Row), .Range("AH" & c.Row), .Range("AK" & c.Row), .Range("AN" & c.Row), _
.Range("AC" & c.Row), .Range("AF" & c.Row), .Range("AI" & c.Row), .Range("AL" & c.Row), .Range("AO" & c.Row))
Else
Set rngBig = Union(rngBig, c, .Range("F" & c.Row & ":G" & c.Row), .Range("H" & c.Row), _
.Range("M" & c.Row), .Range("S" & c.Row), .Range("U" & c.Row), .Range("X" & c.Row), _
.Range("AA" & c.Row), .Range("AD" & c.Row), .Range("AG" & c.Row), .Range("AJ" & c.Row), .Range("AM" & c.Row), _
.Range("AB" & c.Row), .Range("AE" & c.Row), .Range("AH" & c.Row), .Range("AK" & c.Row), .Range("AN" & c.Row), _
.Range("AC" & c.Row), .Range("AF" & c.Row), .Range("AI" & c.Row), .Range("AL" & c.Row), .Range("AO" & c.Row))
End If

Set c = .Columns("D").FindNext(c)
Loop While Not c Is Nothing And c.Address < FirstAddress
End If
End With

rngBig.Copy Sheets("Sheet2").Range("A2")
End Sub
-------------------------
For the selected rows (with all the same text in column D) the copy result to Sheet2 should be in the order as changed now in the code resulting in;

Sheet1 - Sheet2
D - A
F - B
G - C
H - D
M - E
S - F
U - G
X - H
AA - I
AD - J
AG - K
AJ - L
AM - M
AB - N
AE - O
AH - P
AK - Q
AN - R
AC - S
AF - T
AI - U
AL - V
AO - W

But.............
The code copied to Sheet2 A till H in the correct column (oke).
but in column I till W the data is I=AA, J=AB, K=AC till W=AO instead of I=AA, J=AD, K=AG etc..
It looks like the code can, wrote on this way, only handle with columns in the normal order.

Question..... what is the solution. Can somebody explain me what to change in the code :)

regards, Johan