• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Copy paste data

What do you mean by "this code not work in 2003 excel file"?
  • In the first post you have posted an xlsx file which means it is 2007 or later. The file you posted later is xls so it means 2003 or previous.
  • Does the code give some error or it doesn't work per your requirement?
If you care to explain these things then something can be worked out.

Edit:= I see that Marcus has posted a solution. See if it works for you!
 
Abhijeet.

The above file is an XLS file XL 03. Can you please run it at your end and come back with any observations. I apologise for not uploading an XL 03 file earlier.

Take care

Smallman
 
No not work in 2003 also look my data i want till this range the data
 

Attachments

  • RandCols03.xls
    62.5 KB · Views: 2
You see the file macro run then error in this line j = Range("A1", Range("IV1").End(xlToLeft)).Find(ar(1, i)).Column
 
No I don't get that error. If I can't see the error I can't trap the error. It runs really well at my end. Maybe someone else can chime in - does it work on other peoples computers?

Take it easy

Smallman
 
See if this works for you.
Code:
Option Explicit
Sub CopyData()
Dim i As Integer, lastRow As Long
Dim PstRng As Range

lastRow = Range("A" & Rows.Count).End(xlUp).Row
Sheet2.[2:65536].EntireRow.Delete

For i = 1 To 256
    Set PstRng = Sheet2.Range("1:1").Find(Cells(1, i).Value, [A1], xlValues, xlWhole)
    If Not PstRng Is Nothing Then
        Range(Cells(2, i), Cells(lastRow, i)).Copy PstRng.Offset(1, 0)
    End If
Next i

End Sub
 
Shrivallavha column its work but i put in rows till 10000 then its not work
I have specified in my previous message "Its not work" really doesn't tell anything useful. What happens?
The code gives error?
Doesn't give error but does nothing?

Do you care to describe?

Code:
Option Explicit
Sub CopyData()
Dim i As Integer, lastRow As Long
Dim PstRng As Range

lastRow = Cells.Find("*", [A1], xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Sheet2.[2:65536].EntireRow.Delete

For i = 1 To 256
    Set PstRng = Sheet2.Range("1:1").Find(Cells(1, i).Value, [A1], xlValues, xlWhole)
    If Not PstRng Is Nothing Then
        Range(Cells(2, i), Cells(lastRow, i)).Copy PstRng.Offset(1, 0)
    End If
Next i

End Sub
 
Shrivallabha

Welcome to my world!!!! If it helps you mentally, your file works fine for me on my computer. No errors all good.

Take it easy

Smallman
 
No just like my file it is all good. Something is wrong with your computer or your ability to run vba code from your computer.

Have to turn in for the night.

Take care

Smallman
 
Smallman r u use 2007 or then version then put data in last row data in last column then run macro its work tell me
 
no give error but not pull last row data also then it is not work
OK. Try this code.
Code:
Option Explicit
Sub CopyData()
Dim i As Integer, lastRow As Long
Dim PstRng As Range

lastRow = Cells.Find("*", [A1], xlFormulas, xlPart, xlByRows, xlPrevious, False).Row
Sheet2.[2:65536].EntireRow.Delete

For i = 1 To 256
    Set PstRng = Sheet2.Range("1:1").Find(Cells(1, i).Value, [A1], xlValues, xlWhole)
    If Not PstRng Is Nothing Then
        Range(Cells(2, i), Cells(lastRow, i)).Copy PstRng.Offset(1, 0)
    End If
Next i

End Sub

I am not going to upload a sample file ;)

1. I want you to open Visual Basic Editor and replace old code with this one.
2. Then step through the code using F8 and see where it doesn't work per your expectations.
3. Post back the exact line and what did you expect along with the sample file if possible.
 
Thanks for this my problem is solve my data is not whole sheet what ever my data range this macro is work fine
Thanks for ur support
 
Back
Top