Need help copy data from shee1 to sheet2

muzzy

Active Member
Joined
Apr 8, 2014
Messages
333
I am looking for a Formulas or VBA to copy this to sheet 2. If I have this.

Assigned Role
Assigned
1-2-8-26-1-1-11ARTHUR
1-2-8-26-1-1-11CHARLOTTE
Subtotal
1-2-8-26-1-2-13MARSHALL
1-2-8-26-1-2-13MATTHEW
1-2-8-26-1-2-13PASCAL
Subtotal
1-2-8-26-1-1-12ABRIL
1-2-8-26-1-1-12BRIA
1-2-8-26-1-1-12DIANNA
Subtotal
1-2-8-26-2-2-12JERMELL
Subtotal

<colgroup><col><col></colgroup><tbody>
</tbody>

But this is what I need I need the Subtotal to be removed so it will look like this.

Assigned Role
Assigned
1-2-8-26-1-1-11ARTHUR
1-2-8-26-1-1-11CHARLOTTE
1-2-8-26-1-2-13MARSHALL
1-2-8-26-1-2-13MATTHEW
1-2-8-26-1-2-13PASCAL
1-2-8-26-1-1-12ABRIL
1-2-8-26-1-1-12BRIA
1-2-8-26-1-1-12DIANNA
1-2-8-26-2-2-12JERMELL

<colgroup><col><col></colgroup><tbody>
</tbody>

Please can someone help thanks
 
ws_src is the sheet from which you want to copy data i.e. source sheet
ws_dst is the sheet to which you want to copy data to i.e. destination sheet

so please replace the names and it should work.
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
I did what you said and it works on the destination sheet good but it also does the same thing on the source sheet.
 
Upvote 0
if you step through with F8, I think the work is being done on the main page and then being copied over

where as I think you know want to keep the first page with the erroneous formatting

in which case the copy to the other sheet has to be done first and then you do the work there
 
Upvote 0
What do you actually want?

Do you want to keep the source sheet as it is and apply formatting (i.e. deleting rows which contain Subtotal) to the destination sheet?
 
Upvote 0
Hello Muzzy,

here is the code:

Private Sub btnExport_Click()
Dim ws_src As Worksheet, ws_dst As Worksheet
Dim wb_src As Workbook


Set wb_src = ThisWorkbook
Set ws_src = wb_src.Sheets(1)
Set ws_dst = wb_src.Sheets(2)


Dim subTotal As String


subTotal = "Subtotal"


'Get the last filled row number
LastDataRow = ws_src.Range("A" & ws_src.Rows.Count).End(xlUp).Row
rngToCheck = "B2:B" & LastDataRow


rangeToCopy = "A1:B" & LastDataRow
ws_src.Range(rangeToCopy).Copy
ws_dst.Range(rangeToCopy).PasteSpecial

For counter = 2 To LastDataRow
deleteRowRng = "B" & counter

If ws_dst.Range(deleteRowRng).Value = "Subtotal" Then
ws_dst.Rows(counter).Delete
End If
Next

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,470
Messages
6,124,993
Members
449,201
Latest member
Lunzwe73

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