Loop to Copy rows based in Text in to new work book, support with destination

loubdizzy

New Member
Joined
Mar 18, 2021
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
  2. Mobile
  3. Web
Hey guys,

I found this code really helpful initially to go through a sheet and copy out specific row if column A matched the text criteria.

However it copies the data to the exacts same place in the new template I copy too. which now that there are more text criteria groups its getting a little annoying.

Do I need to add in a For ( row count or something). I would like the data to be pasted from A5 in the Template.xlsx.

Suggestions would be welcome, examples I have seen will make me change this up a little too much and there are a lots of these in the script, so trying to reduce too much editing if at all possible.


VBA Code:
With Sheets(4)
    
    For Each Cell In .Range("A4:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        If Cell.Value = "BTB" Then
            .Rows(Cell.Row).Copy Destination:=Workbooks("Template.xlsx").Worksheets("BTB 2021").Rows(Cell.Row)
        End If
    Next Cell

End With

Many thanks
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Hey guys,

I found this code really helpful initially to go through a sheet and copy out specific row if column A matched the text criteria.

However it copies the data to the exacts same place in the new template I copy too. which now that there are more text criteria groups its getting a little annoying.

Do I need to add in a For ( row count or something). I would like the data to be pasted from A5 in the Template.xlsx.

Suggestions would be welcome, examples I have seen will make me change this up a little too much and there are a lots of these in the script, so trying to reduce too much editing if at all possible.


VBA Code:
With Sheets(4)
   
    For Each Cell In .Range("A4:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)
        If Cell.Value = "BTB" Then
            .Rows(Cell.Row).Copy Destination:=Workbooks("Template.xlsx").Worksheets("BTB 2021").Rows(Cell.Row)
        End If
    Next Cell

End With

Many thanks

ok I solved this ...

i changed line

VBA Code:
  .Rows(Cell.Row).Copy Destination:=Workbooks("Template.xlsx").Worksheets("BTB 2021").Rows(Cell.Row)

to ....

VBA Code:
.Rows(Cell.Row).Copy Destination:=Workbooks("Template.xlsx").Worksheets("Weekly Activty Plan").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)

All is ok in the world, keeping up in case others stumble across this issue :)
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,897
Members
449,097
Latest member
dbomb1414

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