Macro help needed

parra1

New Member
Joined
Feb 20, 2008
Messages
38
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
Afternoon all, I have a quick question with regards to a Macro I have written that doesn’t want to seem to work. To describe it I want to take data from one overall worksheet, filter it by “SML” then copy and paste that into a SML worksheet. <o:p></o:p>
<o:p></o:p>
The code I currently have is:<o:p></o:p>
<o:p></o:p>
Private Sub CommandButton2_Click()<o:p></o:p>
ActiveWindow.LargeScroll ToRight:=-1<o:p></o:p>
Columns("A:C").Select<o:p></o:p>
Selection.EntireColumn.Hidden = False<o:p></o:p>
Selection.AutoFilter Field:=3, Criteria1:="sml"<o:p></o:p>
Range("A1:W7").Select<o:p></o:p>
Selection.Copy<o:p></o:p>
Sheets("SML Data").Select<o:p></o:p>
Range("A347:W347").Select<o:p></o:p>
ActiveSheet.Paste<o:p></o:p>
ActiveWindow.SmallScroll ToRight:=11<o:p></o:p>
End Sub<o:p></o:p>
<o:p></o:p>
<o:p></o:p>
The bit highlighted in yellow is highlighted as an error section.<o:p></o:p>
<o:p></o:p>
Could anyone please help?<o:p></o:p>
<o:p></o:p>
Thank you in advance!<o:p></o:p>
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Is the filter already set on the range, if not maybe try:
Rich (BB code):
Columns("A:C").Hidden = False
Range("A1:C1").AutoFilter
Range("A1:C1").AutoFilter Field:=3, Criteria1:="sml"
Range("A1:W7").Copy Destination:= Sheets("SML Data").Range("A347:W347")
Hope that helps.

EDIT: I Have no clude why it keeps splitting up my code tags? Has anyone else noticed this, this is the 2nd time within this week?
 
Last edited by a moderator:
Upvote 0
cant see any yellow highlighted code. What error do you get and where?

The code seems fine, but you dont need the active scroll lines in there, and a good tip is to give your buttons contextual names e.g. instead of CommandButton_2, call it SML_Move or something.
 
Upvote 0
I dont see anything highlighted in yellow. I took the liberty of tightening your code a little.

I am assuming that Column A is completely filled with no empty cells and that you want to copy your data to sheet SML into the first empty row - in your code row 347 ...

Code:
Private Sub CommandButton2_Click()

    Columns("A:W").Select
    Selection.EntireColumn.Hidden = False
    Selection.AutoFilter Field:=3, Criteria1:="sml"
    Range(Cells(1,"A"),Cells(Cells(rows.count,1).end(xlup).row, "W").cells.specialcells(xlcelltypevisible).copy _
destination:=Sheets("SML Data").Cells(Cells(rows.count,1).end(xlup).row + 1, "A")

End Sub
 
Upvote 0

Forum statistics

Threads
1,221,596
Messages
6,160,711
Members
451,665
Latest member
PierreF

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