conditional copying

osaben

Board Regular
Joined
Mar 17, 2010
Messages
62
Office Version
  1. 365
Platform
  1. Windows
<!-- / icon and title --><!-- message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_start --><!-- END TEMPLATE: ad_showthread_firstpost_start -->looking to copy any entire row from the first sheet to the second when the word "total" exists in that row in the first sheet. I want to copy it to the next available row in the second sheet. (i.e. no blank rows)

Any suggestions on the code?



 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
maybe something like
Code:
Sub FindTotal()
Sheets("Sheet2").Activate
    lr = Cells(Rows.Count, 1).End(xlUp).Row + 1
Sheets("Sheet1").Activate

Set Rng = Range("a1:z" & Cells(Rows.Count, 1).End(xlUp).Row)
For Each cell In Rng
If cell.Value = "Total" Or cell.Value = "total" Then
    cell.EntireRow.Copy Destination:=Worksheets("Sheet2").Range("A" & lr)
    lr = lr + 1
End If

Next cell

End Sub
change Sheet1 and Sheet2 to what ever you use
 
Upvote 0
rassten, Thank you for your reply. When I try to run this I get the following error:

Run-time error '28'
Out of stack space

any ideas what this is?
 
Upvote 0
I tried applying this code a second time. I think the issues might also be the way I am doing it.

I already have three seperate macros in place. That run via a command button on sheet 1. I went into Developer/Visual Basic/ View Code. I enter the addrtional code right below the last one. If figured since there was no cammand button, I would do the following to make the last/4th macro run. Developer/Macros/a macro named Dheet1.FindTotal appears. I highlight it an select Run....nothing happens.....no errors...no copying occurs to sheet 2.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,844
Members
452,948
Latest member
UsmanAli786

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