Macro problem with If statement.

darekknox

New Member
Joined
Feb 19, 2015
Messages
31
Hi All,
I am working on some VBA code and got stuck with "If" statement.
In general I want macro to filter proper columns basing o cell values and copy paste the result to another tab. This is my code so far:

Code:
Sub test()
Sheets("Tommy").Activate


'Hotw to loop it so the macro can be done for each row?


Select Case Range("h3").Value
    Case Is = "Tab1"
    Range("k3:s3").Copy
    Sheets("Tab1").Activate
    Range("c2:k2").PasteSpecial
    
    
    
    Case Is = "Tab2"
    Range("k3:s3").Copy
    Sheets("Tab2").Activate
    Range("c2:k2").PasteSpecial
    
    End Select
    
    Sheets("Tommy").Activate
    
    'I want the macro to filter column J of Tab2/Tab1 to show only rows with "Y" in column J, and then copy columns from B to H and paste them to "Fianl" tab.
    If Range("G3") = "Global" And Range("h3") = "Tab2" Then
    
    Sheets("Tab2").Select
    Rows("5:5").Select
    Range("J5").Activate
    Selection.AutoFilter
    ActiveSheet.Range("$a$5:$m$5").AutoFilter field:=11, Criteria1:="<>"
    End If
    
  
    
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Forum statistics

Threads
1,215,063
Messages
6,122,934
Members
449,094
Latest member
teemeren

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