Help, Need one range fixed.

Bub_the_Zombie

Board Regular
Joined
Nov 1, 2016
Messages
53
I have made a macro using the macro recorder to take all instances of a name from a list and copy them (and the range of data) to a different area on the page. The macro works great when it is run from the VBA screen, but not when I try to apply it to a command button.

I defined the WS to the correct sheet it needs to work on, but one piece of it stays wrong with each attempt, either range or "object doesn't support this property or method". I put the results of the macro recorder, then my attempt to clean it up and apply it to a command button in separate code boxes below.

Currently the problem that is being highlighted when it is debugged is
Code:
WS.Range("B7").Paste

Could someone please tell me how to fix the second code.

Code:
Sub FIND_TOM()

    ActiveWindow.SmallScroll Down:=-3
    Range("B100:F139").Select
    Selection.AutoFilter
    ActiveSheet.Range("$B$100:$F$139").AutoFilter Field:=5, Criteria1:="TOM"
    ActiveWindow.SmallScroll Down:=-12
    Selection.Copy
    ActiveWindow.SmallScroll Down:=-84
    Range("B7").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    Selection.AutoFilter
End Sub

Code:
Private Sub daily_sheets_Click()

Dim WS As Worksheet
Set WS = Sheets("daily sheets")


    WS.Range("B100:F139").AutoFilter
    WS.Range("$B$100:$F$139").AutoFilter Field:=5, Criteria1:="TOM"
    WS.Range("B100:F147").Copy
    
    WS.Range("B7").Paste 'this is the problem
    
    Application.CutCopyMode = False
    Selection.AutoFilter
    
End Sub
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
hi

would it not work if you simply put

call FIND_TOM

within your command button and remove the rest?

Dave
 
Upvote 0
this syntax will copy and paste your data.

Code:
WS.Range("B100:F147").Copy  WS.Range("B7")

Another way is to first select B7 then use ActiveSheet.Paste
 
Last edited:
Upvote 0
JLGWhiz, thanks! Works perfect!

Squidd, still learning excel, really only two weeks out the gate. That is an awesome command, is there a way to get that command to work from another work sheet? In the above example the button to activate that code is on a separate sheet (sheet 1) and the actions take place on (sheet 2).
 
Upvote 0
you can call a macro from any command button and it will execute the code that is in the macro, so if that macros said,

do something on sheet 1, do something on sheet 2 and finally do something on sheet 3, then the macro will do this. no matter where you call the macro.

dave
 
Upvote 0

Forum statistics

Threads
1,214,644
Messages
6,120,709
Members
448,983
Latest member
Joaquim_Baptista

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