Macro to copy and paste all rows of data in between two words

Dear Group

This is probably somewhere here on this site but I cannot seem to
track it down so I hope someone can help me.

I am looking for a macro that can find the word "Start" in column B
and then move one row and select all the rows until the word "End" is
found in Column B".

Then copy from sheet named "Datafrom" to sheet named "Datato".

I really hope someone can help with this.

Thanks very much in advance.
0
Stuart
4/22/2010 10:10:20 AM
excel.programming 6508 articles. 2 followers. Follow

5 Replies
1139 Views

Similar Articles

[PageSpeed] 27

Try;

Sub DoIt()
 Dim rRange As Range

 On Error Resume Next
 Set rRange = Range(Range("A:A").Find("Start", _
        Cells(1, 1), xlFormulas, _
            xlPart, xlByRows, xlNext, False), _
            Range("A:A").Find("End", _
        Cells(1, 1), xlFormulas, _
            xlPart, xlByRows, xlNext, False))
On Error GoTo 0

 If Not rRange Is Nothing Then
  Application.Goto rRange.EntireRow
 Else
   MsgBox "'Start' or 'End' not found"
 End If
End Sub



-- 
Regards
Dave Hawley
www.ozgrid.com
"Stuart" <swilson2006@gmail.com> wrote in message 
news:9f515189-7304-4d30-ad1a-596e65cdfbdf@q15g2000yqj.googlegroups.com...
> Dear Group
>
> This is probably somewhere here on this site but I cannot seem to
> track it down so I hope someone can help me.
>
> I am looking for a macro that can find the word "Start" in column B
> and then move one row and select all the rows until the word "End" is
> found in Column B".
>
> Then copy from sheet named "Datafrom" to sheet named "Datato".
>
> I really hope someone can help with this.
>
> Thanks very much in advance. 

0
ozgrid
4/22/2010 10:29:09 AM
Dave

Thanks for this.

I made a slight change to the code as follows so that it would look up
column B.

> Sub DoIt()
> =A0Dim rRange As Range
>
> =A0On Error Resume Next
> =A0Set rRange =3D Range(Range("B:B").Find("Start", _
> =A0 =A0 =A0 =A0 Cells(1, 2), xlFormulas, _
> =A0 =A0 =A0 =A0 =A0 =A0 xlPart, xlByRows, xlNext, False), _
> =A0 =A0 =A0 =A0 =A0 =A0 Range("B:B").Find("End", _
> =A0 =A0 =A0 =A0 Cells(1, 2), xlFormulas, _
> =A0 =A0 =A0 =A0 =A0 =A0 xlPart, xlByRows, xlNext, False))
> On Error GoTo 0
>
> =A0If Not rRange Is Nothing Then
> =A0 Application.Goto rRange.EntireRow
> =A0Else
> =A0 =A0MsgBox "'Start' or 'End' not found"
> =A0End If
> End Sub

Is there a way to add a forumla automatically in column I for all the
rows selected above.  The formula would be =3D"DATA"&" - "&B8&" - "&C8&"
- "&E8&"EUR".

Also your macro above does not copy all the above selected rows and
paste them into another worksheet called "Datato".

Can this be added?

Kind Regards,

Stuart

On Apr 22, 11:29=A0am, "ozgrid.com" <d...@ozgrid.com> wrote:
> Try;
>
> Sub DoIt()
> =A0Dim rRange As Range
>
> =A0On Error Resume Next
> =A0Set rRange =3D Range(Range("A:A").Find("Start", _
> =A0 =A0 =A0 =A0 Cells(1, 1), xlFormulas, _
> =A0 =A0 =A0 =A0 =A0 =A0 xlPart, xlByRows, xlNext, False), _
> =A0 =A0 =A0 =A0 =A0 =A0 Range("A:A").Find("End", _
> =A0 =A0 =A0 =A0 Cells(1, 1), xlFormulas, _
> =A0 =A0 =A0 =A0 =A0 =A0 xlPart, xlByRows, xlNext, False))
> On Error GoTo 0
>
> =A0If Not rRange Is Nothing Then
> =A0 Application.Goto rRange.EntireRow
> =A0Else
> =A0 =A0MsgBox "'Start' or 'End' not found"
> =A0End If
> End Sub
>
> --
> Regards
> Dave Hawleywww.ozgrid.com"Stuart" <swilson2...@gmail.com> wrote in messag=
e
>
> news:9f515189-7304-4d30-ad1a-596e65cdfbdf@q15g2000yqj.googlegroups.com...
>
>
>
> > Dear Group
>
> > This is probably somewhere here on this site but I cannot seem to
> > track it down so I hope someone can help me.
>
> > I am looking for a macro that can find the word "Start" in column B
> > and then move one row and select all the rows until the word "End" is
> > found in Column B".
>
> > Then copy from sheet named "Datafrom" to sheet named "Datato".
>
> > I really hope someone can help with this.
>
> > Thanks very much in advance.

0
Stuart
4/22/2010 11:13:20 AM
Stuart,

try this

Sub CopyData()
Set srcSht = Sheets("Datafrom")
Set dstSht = Sheets("Datato")
Dim lastrow As Long
Dim StRow As Range
Dim EndRow As Range
Set StRow = srcSht.Range("B:B").Find("Start", LookIn:=xlValues, 
lookat:=xlWhole)
Set EndRow = srcSht.Range("B:B").Find("End", LookIn:=xlValues, 
lookat:=xlWhole)
If StRow Is Nothing Or EndRow Is Nothing Then
    MsgBox "Range Not Found"
        Exit Sub
End If
    lastrow = dstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
    srcSht.Rows(StRow.Row & ":" & EndRow.Row).Copy 
Destination:=dstSht.Range("A" & lastrow)
End Sub

-- 
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that 
introduces the fewest assumptions while still sufficiently answering the 
question.


"Stuart" wrote:

> Dear Group
> 
> This is probably somewhere here on this site but I cannot seem to
> track it down so I hope someone can help me.
> 
> I am looking for a macro that can find the word "Start" in column B
> and then move one row and select all the rows until the word "End" is
> found in Column B".
> 
> Then copy from sheet named "Datafrom" to sheet named "Datato".
> 
> I really hope someone can help with this.
> 
> Thanks very much in advance.
> .
> 
0
Utf
4/22/2010 11:14:01 AM
Mike

Thanks for your reply.

Do you happen to know how I can add the following formula into the
last column of data?

=3D"DATA"&" - "&B8&" - "&C8&"

I want to add the above formula into the last column where there are
rows containing text in the first cell of that row.

I appreciate that this is a rather complicated request but I was
hoping that someone on the forum would be able to assist.

Kind Regards,

Stuart


On Apr 22, 12:14=A0pm, Mike H <Mi...@discussions.microsoft.com> wrote:
> Stuart,
>
> try this
>
> Sub CopyData()
> Set srcSht =3D Sheets("Datafrom")
> Set dstSht =3D Sheets("Datato")
> Dim lastrow As Long
> Dim StRow As Range
> Dim EndRow As Range
> Set StRow =3D srcSht.Range("B:B").Find("Start", LookIn:=3DxlValues,
> lookat:=3DxlWhole)
> Set EndRow =3D srcSht.Range("B:B").Find("End", LookIn:=3DxlValues,
> lookat:=3DxlWhole)
> If StRow Is Nothing Or EndRow Is Nothing Then
> =A0 =A0 MsgBox "Range Not Found"
> =A0 =A0 =A0 =A0 Exit Sub
> End If
> =A0 =A0 lastrow =3D dstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
> =A0 =A0 srcSht.Rows(StRow.Row & ":" & EndRow.Row).Copy
> Destination:=3DdstSht.Range("A" & lastrow)
> End Sub
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
>
> "Stuart" wrote:
> > Dear Group
>
> > This is probably somewhere here on this site but I cannot seem to
> > track it down so I hope someone can help me.
>
> > I am looking for a macro that can find the word "Start" in column B
> > and then move one row and select all the rows until the word "End" is
> > found in Column B".
>
> > Then copy from sheet named "Datafrom" to sheet named "Datato".
>
> > I really hope someone can help with this.
>
> > Thanks very much in advance.
> > .

0
Stuart
4/23/2010 8:07:43 PM
Hi Mike

Do you know what I should modify in your code to paste the data to the
new sheet as values only?

Kind Regards,

Stuart

On Apr 23, 9:07=A0pm, Stuart <swilson2...@gmail.com> wrote:
> Mike
>
> Thanks for your reply.
>
> Do you happen to know how I can add the following formula into the
> last column of data?
>
> =3D"DATA"&" - "&B8&" - "&C8&"
>
> I want to add the above formula into the last column where there are
> rows containing text in the first cell of that row.
>
> I appreciate that this is a rather complicated request but I was
> hoping that someone on the forum would be able to assist.
>
> Kind Regards,
>
> Stuart
>
> On Apr 22, 12:14=A0pm, Mike H <Mi...@discussions.microsoft.com> wrote:
>
>
>
> > Stuart,
>
> > try this
>
> > Sub CopyData()
> > Set srcSht =3D Sheets("Datafrom")
> > Set dstSht =3D Sheets("Datato")
> > Dim lastrow As Long
> > Dim StRow As Range
> > Dim EndRow As Range
> > Set StRow =3D srcSht.Range("B:B").Find("Start", LookIn:=3DxlValues,
> > lookat:=3DxlWhole)
> > Set EndRow =3D srcSht.Range("B:B").Find("End", LookIn:=3DxlValues,
> > lookat:=3DxlWhole)
> > If StRow Is Nothing Or EndRow Is Nothing Then
> > =A0 =A0 MsgBox "Range Not Found"
> > =A0 =A0 =A0 =A0 Exit Sub
> > End If
> > =A0 =A0 lastrow =3D dstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row +=
 1
> > =A0 =A0 srcSht.Rows(StRow.Row & ":" & EndRow.Row).Copy
> > Destination:=3DdstSht.Range("A" & lastrow)
> > End Sub
>
> > --
> > Mike
>
> > When competing hypotheses are otherwise equal, adopt the hypothesis tha=
t
> > introduces the fewest assumptions while still sufficiently answering th=
e
> > question.
>
> > "Stuart" wrote:
> > > Dear Group
>
> > > This is probably somewhere here on this site but I cannot seem to
> > > track it down so I hope someone can help me.
>
> > > I am looking for a macro that can find the word "Start" in column B
> > > and then move one row and select all the rows until the word "End" is
> > > found in Column B".
>
> > > Then copy from sheet named "Datafrom" to sheet named "Datato".
>
> > > I really hope someone can help with this.
>
> > > Thanks very much in advance.
> > > .

0
Stuart
4/27/2010 6:21:26 AM
Reply:

Similar Artilces:

Word Quits when I close document window
I'm running Office:mac X on OS 10.1.5. When I close a window in word, it usually quits with an error message that says it quit unexpectedly and that other applications and the system are not affected. This also happened when I was running Word for Mac '98 on Classic 9.2.2, but not as consistently. Does anyone know what is going on and how to fix it? In article <0aef01c3789d$3d5f4c00$a001280a@phx.gbl>, "Liz" <S0journer@aol.com> wrote: > I'm running Office:mac X on OS 10.1.5. When I close a > window in word, it usually quits with an error message th...

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

deleting rows #4
In microsoft encell 2000 when i delete a row (say row 5) the row disapears but so does the row number then all other rows are moved up is there a way to delete the row and keep the number 5? The row number shouldn't disappear unless you are hiding the row, not deleting it -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS "Doctorpc631" <doctorpc631@aol.com> wrote in message news:e4FaNYV4EHA.1260@TK2MSFTNGP12.phx.gbl... > In microsoft encell 2000 when i delete a row (say row 5) the row > disapears > but s...

Hyperlink to a bookmark created in Word and copied to Windows Mail don't work
A bookmark created in Windows Mail along with the hyperlink to it don't work when copied to Windows Mail for e-mailing I get an error message: mid://00000174/ ...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Copying a variable nuimber of rows
I want to copy the most recent 10 rows (excluding the header row) from worksheet A to worksheet B. My problem is how do I define a variable number of rows if there are fewer than 10 lines completed? I do not want to copy any blank lines. I am fairly new to VBA and am struggling to work out the code for this so any help will be gratefully appreciated. John Try With Activesheet LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row if LastRow > 10 Then FirstRow = LastRow - 9 Else FirstRow = 1 EndIf ...

Word uses up a lot of memory
When I open a file of Word97-03, it uses up a lot of memory. eg. My RAM is 4GB and it uses up 1,002,188K for WINWORD.EXE Sorry, but this newsgroup is for questions about Access, the database product that's part of Office Professional. You'd be best off reposting your question to a newsgroup related to Word. Should you do that, it might help the responder to know more about your setup. What version of Word are you using? What Operating System? What else is running at the same time and so on. Good luck! -- Doug Steele, Microsoft Access MVP http://I.Am/DougSteele...

Stupid 'Copy' button
Hi, Why does RMS preserve quantity and commited values & serial numbers (amongst others) when you are use the 'copy' function for setting up a new code - this is crazy!!!! Is there an SQL script available I can use to set the correct committed values for any items which have been created by the 'copy' button? I am going to have to tell the customer perform a physical inventory to get the quantity on hand values correct - but committed is more important to fix straight away as they use this for ordering purposes. Can anyone help me? Regards, Jason. ...

Making a domain appear in two places?
Assumptions: 1. We are running Exchange 2003 (SBS 2003 Server) in our office and are running a Windows domain (not to be confused with an internet domain). 2. We have a domain let's call "domain.com" and it is working for receiving email. Problem: We want to place another Exchange box in our datacenter. The datacenter is completely remote from our office. It runs our production web site. It is its own Windows domain and is NOT trusted. How do I?? 1. We want the Exchange Server at the datacenter to receive all email for "domain.com" 2. We want to have two mailbox...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

Disabling Copy
I have an excel sheet which is protected. When i right click on a cell it can allow me to copy the contents. How can i make the copy to be disabled? Any one out there with an idea? Thanks -- pkrono ------------------------------------------------------------------------ pkrono's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=19532 View this thread: http://www.excelforum.com/showthread.php?threadid=346874 You can do this with Excel 2002/2003. With code you could disable a right-click, but you could still use Edit->Copy in Excel 2000 and earlier. "pk...

charting data with multiple series
I have a data set in this format: Temp Pressure Mass=115 2.2 897 4.1 752 6.3 631 8.5 555 Mass=125 1.3 999 4.6 888 8.9 777 9.6 600 Mass=130 3.6 987 4.5 876 6.9 654 8.0 555 and so on... Using an XY Scatter Graph, I want to plot Temp vs. Pressure for each data series. I want the labels in the left column to show up in the legend. Any suggestions on how to select the data? Thanks, Mary [This follo...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

How to Use One PST file on Two Computers?
Hello: I have a desktop machine with a pst file in my Outlook 2003. I would like to copy this pst file to my laptop. How do I synchronize the same file on 2 machines so I won't get duplicate e-mails? I use one premium Yahoo e-mail account and several free Yahoo accounts with YahooPOPs.. Thanks in advance, Spudy Hi Spudy, it is not possible by default to share PST files. A list of a list of third-party synctools are also on this site: http://www.slipstick.com/outlook/sync.htm On the Microsoft Office Marketplace site is a list of third-party messaging tools: http://office.microsoft.com...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Changing Rows to Columns
Is it possible to easily rotate a spreadsheet or part of a spreadshet, to change the data in rows to columns? Do to a sorting problem in the charts I create, it seems I have to sort the data in the spreadsheet first. Any help would be appreciated. Hi, Sure is a way. select & copy your data. then select the cell where you want to re-paste; right-click and select paste special; in the dialog box check "transpose". Ok. jeff >-----Original Message----- >Is it possible to easily rotate a spreadsheet or part of a >spreadshet, to change the data in rows to columns? D...

I keep having to force quit MS Word It also Freezes screen often
Operating System: Mac OS X 10.5 (Leopard) Processor: Intel I keep having to force quit MS Word. It won't quit when I hit quit. It also seems to Freeze the screen often and I have to restart. Help? Without having so much as an indication what version of Office you're using it's impossible to suggest anything other than the fundamentals; 1- Make sure your version of Office is fully updated, 2- Make sure OS X is fully updated, 3- Run Disk Utility - Repair Disk Permissions, 4- Restart your Mac. If you continue to have a problem reply here with version specific in...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Sum of Two Union Queries
Hello, I have the following SQL that produces two record totals (as it should). But I want to SUM those two values from within the same query. Rather than create a second query that SUMs the two values from the first query: SELECT Count(*) AS SubCount FROM [MyTable1] WHERE (([MyTable1].UNIQUEUSER)="JOHNSMITH") UNION ALL SELECT Count(*) AS SubCount FROM [MyTable2] WHERE (([MyTable2].SWCASSIGNEDUSER)="JOHNSMITH"); The results I get are: SubCount -------------- 380 2 I've tried "wrapping" that entire SQL code inside of a SELECT SUM, but upon execution it ...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Copy picture from word 2003 to word 2007
When I copy a document with a picture from 2003 to 2007 the picture ends up with what looks like a bunch of lines - horizontal. Any way to get rid of this? Your best bet would be to right click the picture in your 2003 document and save the picture to your computer. After this is completed, open Word 2007 and click insert picture. Now browse your computer and find that picture you saved. I'm surprised this happened, but I'm guessing its a compatibility issue between 2003 and 2007. "Daisy" wrote: > When I copy a document with a picture from 2003 to 2007...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

New SBS2008 domain Outlook won't setup on last two devices: suspect firewall
New site almost finished. Office is a bunch of PhD engiineer types that have to fiddle with stuff. Also they all know MS stuff sucks. Last two workstations (Vista and XP) joined to domain fine. Open Outlook 2007 and it stalls and never sets up profile, error must be connected to server to work! Network fully visible. I believe owner has 'tinkered' with sbs2008 firewall during this time. Need pointer on when next to go. Could firewall change stop the setup? TIA Did you create users with wizards did you connect the PC's with http://connnect is the DHCP server th...