Macro to Copy, Paste & Filter into a different worksheet

shakeregg

New Member
Joined
Sep 2, 2018
Messages
39
Hey all,

Hopefully someone will be able to help!

I have digits ranging from 0 - 100 in K4:K60 in a worksheet called ‘Raw Data’. There is also written contents in B4:B60 and C4:C60 in the same worksheet (Raw Data). What I am trying to do is identify any digits in Column K that are under 60 and copy and paste the contents of this cell along with the equivalent B & C cells to another worksheet called LSQ.

For example, if K6 = 55 then I would like B6, C6 & K6 to be copied and pasted to LSQ. K12 = 42 then B12, C12 & K12 would be copied and pasted etc.

Column B contents from ‘Raw Date’ to be pasted in Column B4 onwards in LSQ.
Column C contents from’Raw Data’ to be pasted in Column C4 onwards in LSQ.
Column K digits from ‘Raw Data’ to be pasted in Column D4 onwards in LSQ.

Ideally I would like Column D in LSQ to be automatically filtered low to high.

Hopefully this makes sense and apologies if it doesn’t!

Any help would be really appreciated!!
 
Hey VCoolio.................. here's the link sorry for the delay in responding! It's a mock copy of the actual spreadsheet but it accurately translates.

https://www.dropbox.com/s/rxlxsz3l30u0kew/Test.xlsm?dl=0

So ideally when the macro runs...............hopefully what should happen is for any scores (in K) under 60........... B,C & K will be copied over to LSQ and then be sorted lowest to hightest.

Cheers again!
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hello Shakeregg,

Two little alterations to the code should do it for you:-


Code:
Sub Test()

        Dim ws As Worksheet: Set ws = Sheets("Raw Data")
        Dim sh As Worksheet: Set sh = Sheets("LSQ")
        Dim lr As Long: lr = ws.Range("[COLOR=#ff0000]B[/COLOR]" & Rows.Count).End(xlUp).Row
         
Application.ScreenUpdating = False

        ws.Range("K4", ws.Range("K" & ws.Rows.Count).End(xlUp)).AutoFilter 1, "<" & 60
        Union(ws.Range("B5:C" & lr), ws.Range("K5:K" & lr)).Copy
        sh.Range("B" & Rows.Count).End(3)(2).PasteSpecial xlValues
        ws.[[COLOR=#ff0000]K4[/COLOR]].AutoFilter
        sh.Range("B5", sh.Range("D" & sh.Rows.Count).End(xlUp)).Sort sh.[D5], 1
        
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

The bits in red font are the alterations.
With the lr declaration, I had assumed that you were using Column A in the Raw Data sheet.
The "filter off" is now set on K4 not K3.

I hope that this helps.

Cheerio,
vcoolio.
 
Last edited:
Upvote 0
it's like spreadsheet magic................... thank you!!

just checking is there anyway that the old contents in LSQ can be deleted or if not written over?
 
Upvote 0
Hello Shakeregg,

Another addition as follows (in blue this time) should take care of that:-


Code:
Sub Test()

        Dim ws As Worksheet: Set ws = Sheets("Raw Data")
        Dim sh As Worksheet: Set sh = Sheets("LSQ")
        Dim lr As Long: lr = ws.Range("B" & Rows.Count).End(xlUp).Row
         
Application.ScreenUpdating = False
        
        [COLOR=#0000ff]sh.[B4].CurrentRegion.Offset(1).ClearContents[/COLOR]
        ws.Range("K4", ws.Range("K" & ws.Rows.Count).End(xlUp)).AutoFilter 1, "<" & 60
        Union(ws.Range("B5:C" & lr), ws.Range("K5:K" & lr)).Copy
        sh.Range("B" & Rows.Count).End(3)(2).PasteSpecial xlValues
        ws.[K4].AutoFilter
        sh.Range("B5", sh.Range("D" & sh.Rows.Count).End(xlUp)).Sort sh.[D5], 1
        
Application.CutCopyMode = False
Application.ScreenUpdating = True

End Sub

Test it all in a copy of your worbbook first.

Cheerio,
vcoolio.
 
Upvote 0
You're welcome Shakeregg.
I'm glad that I was able to help.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,331
Members
452,636
Latest member
laura12345

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