Move copany 2 data to new sheet excel VBA

udarawic

New Member
Joined
Dec 29, 2014
Messages
29
My report comes with two company data and when Cell c data say "Company2" I need to move that row and all the rows below to sheet 2.

Can someone help me?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Maybe this
Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = 2 To lr
    If Range("C" & r).Value = "Company2" Then
        Rows(r & ":" & lr).Copy Destination:=Sheets("Sheet2").Range("A2")
        Exit Sub
    End If
Next r
End Sub
 
Upvote 0
Is "Company2" spelled exactly as you have posted ??
AND in the same Case ??
Also, is there data in Column "A"
 
Upvote 0
I think the code needs to be changed to: Note red part changed.
Code:
lr = Cells(Rows.Count, "[SIZE=2][/SIZE][COLOR="#FF0000"]C[/COLOR]").End(xlUp).Row
 
Upvote 0
That thought had crossed my mind but I was concerned that the "Company2" may have been a Sub heading and not in every row.
That's why I went with Col "A" and then queried that in my previous post..(y)
 
Upvote 0
This change not doing anything either? :(


That thought had crossed my mind but I was concerned that the "Company2" may have been a Sub heading and not in every row.
That's why I went with Col "A" and then queried that in my previous post..(y)
 
Upvote 0
You didn't answer any of my questions in Post #4
 
Upvote 0
In that case can you either post a small sample here using the HTML Maker in my tag
OR
Upload the worksheet to Dropbox and post the link back here !


Also, are you placing the code in a standard module AND making the data sheet that needs to be copied the Activesheet ?
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,972
Members
448,537
Latest member
Et_Cetera

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