Copy/Paste Account Names Starting With "A"

wayneshirley

Board Regular
Joined
Jun 23, 2003
Messages
140
Hi There,

I need to add some code to my macro that will recognise account names in column C (sheet 1) that start with the letter "A" and copy those rows into sheet 2 (starting at cell A2.)

Can anyone help me please?

Thank you.
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

SteveO59L

Well-known Member
Joined
Apr 21, 2004
Messages
7,896
Application.ScreenUpdating = False
Dim c As Range, rng
Dim Acc_Name As String
Set rng = Range("c3:c10")
For Each c In rng
If Left(c, 1) = "A" Then
Acc_Name = c
Sheets("Sheet2").Select

LastRow = Range("a" & Rows.Count).End(xlUp).Row

Range("a" & LastRow).Select

Selection.Offset(1, 0).Select

Selection = Acc_Name
Acc_Name = ""
Sheets("Sheet1").Activate
End If
Next c
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,926
Office Version
  1. 365
Platform
  1. Windows
Hi There,

I need to add some code to my macro that will recognise account names in column C (sheet 1) that start with the letter "A" and copy those rows into sheet 2 (starting at cell A2.)

Can anyone help me please?

Thank you.
Unless your dataset is fairly large, you may not see the difference, but this should be a bit faster than looping through each row.

Also, I may be wrong but I think you are saying that you want the whole row copied, not just the account code? If not, just remove .EntireRow from the code below.

<font face=Courier New><br><SPAN style="color:#00007F">Sub</SPAN> FilterAndCopy()<br>    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Sheets("sheet 1")<br>        <SPAN style="color:#00007F">With</SPAN> .Range("C1", .Range("C" & Rows.Count).End(xlUp))<br>            .AutoFilter Field:=1, Criteria1:="=A*"<br>                .Offset(1).SpecialCells(xlCellTypeVisible).EntireRow.Copy _<br>                    Destination:=Sheets("sheet 2").Range("A2")<br>            .AutoFilter<br>        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br>    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN><br></FONT>
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,224
Messages
5,594,914
Members
413,952
Latest member
JGer

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
Top