msg box to apply filter

K

Kirsty

Hi,

I want a macro that has a message box to ask for input and then filters the
data based on hte input. How would I go about this?
 
R

ryguy7272

With your data on Sheet1, run this code:
Sub CopyCA()

Dim DestSheet As Worksheet
Set DestSheet = Worksheets("Sheet2")

Dim sRow As Long
Dim dRow As Long
Dim sCount As Long
sCount = 0
dRow = 0

myword = InputBox("Enter items to search for.")

For sRow = 1 To Range("A65536").End(xlUp).Row

If Cells(sRow, "A") Like "*" & myword & "*" Then
sCount = sCount + 1
dRow = dRow + 1
Cells(sRow, "A").Copy Destination:=DestSheet.Cells(dRow, "A")
End If
Next sRow

MsgBox sCount & " Significant rows copied", vbInformation, "Transfer Done"

End Sub


The results are copied/pasted to Sheet2.

HTH,
Ryan---
 
K

Kirsty

I am getting an error on the line
If Cells(sRow, "A") Like "*" & myword & "*" Then, any suggestions?

Sub CopyCA()

Dim DestSheet As Worksheet
Set DestSheet = Worksheets("Sheet2")

Dim sRow As Long
Dim dRow As Long
Dim sCount As Long
sCount = 0
dRow = 0

myword = InputBox("Enter required week.")

For sRow = 1 To Range("A65536").End(xlUp).Row

If Cells(sRow, "A") Like "*" & myword & "*" Then
sCount = sCount + 1
dRow = dRow + 1
Cells(sRow, "A").Copy Destination:=DestSheet.Cells(dRow, "A")
End If
Next sRow

MsgBox sCount & " Significant rows copied", vbInformation, "Transfer Done"

End Sub
 
M

Mike Fogleman

Sub Filter()
Dim rng As Range
Dim MyCrit As String

MyCrit = InputBox("Enter Filter Criteria")
Set rng = Range("E1:F8")
rng.AutoFilter Field:=1, Criteria1:=MyCrit
End Sub

Mike F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top