Macro to find, copy, paste data with changing stating points

scoutzilla

New Member
Joined
Aug 7, 2012
Messages
7
Greetings all and Happy Holidays.

My problem seems so simple I thought I could come up with a solution on my own, but after working on this for days, I ask for help.

I import .txt data file then need to find where where my data starts (TIME), the number of columns, the number of rows, copy all and paste to Sheet "Clean Data". I can't seem to come up with a Macro that will do this. Here is a sample of what my data might look like:

Number of Rows
Above
TIME
Changes
TIMERange ofdatawould start withTIMEthen endwithempty cells
0222222222222
1444444444444
2666666666666
3888888888888
4101010101010101010101010
5121212121212121212121212


<colgroup><col><col><col><col><col><col><col><col><col><col span="2"><col><col><col><col></colgroup><tbody>
</tbody>
Cheers!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I don't know if you mean the example is for 'Before' or 'After', but on the assumption that it is 'Before' then try this.
Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, fn As Range
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
lr = sh1.Cells.Find("*", , xlValues, xlPart, xlByRows, xlPrevious).Row
Set fn = sh1.Range("A:A").Find("Time", , xlValues, xlWhole, xlByRows, xlPrevious)
    If Not fn Is Nothing Then
        sh1.Range(fn, sh1.Cells(lr, fn.Column)).EntireRow.Copy sh2.Cells(Rows.Count, 1).End(xlUp)(2)
    End If
End Sub
 
Upvote 0
JLGWhiz, Wow 10 lines of code, Neat Slick and works like it should. Thanks so much for the help!
And quick response. I'm amazed, wish I could code like that!!

Cheers Mate!!
 
Upvote 0
JLGWhiz, Wow 10 lines of code, Neat Slick and works like it should. Thanks so much for the help!
And quick response. I'm amazed, wish I could code like that!!

Cheers Mate!!
You can code like that if you do a lot of research, participate in the forums and apply what you know to a personal project. That is essentially how I learned. The research was to understand the technical aspects of Excel parameters and limitations and how VBA operates to use those Excel attributes. I have been doing it for over 20 years and am still learning new stuff daily. So don't be discouraged if you can't write concise code after a couple of weeks. It takes time.
Regards, JLG
 
Upvote 0

Forum statistics

Threads
1,215,221
Messages
6,123,699
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top