bsharath
asked on
Need a macro to search and results in excel.
Hi,
I have uploaded a excel fine.I have all data in Sheet 1.I have the search fields in Sheet 2.What i want is when i enter any data in Sheet 2 colum 2.It has to copy the full lines found to a new sheet.
EX:
Say
I put 512 in the Ram box.It has to search the sheet 1 and copy all Rams with 512.
http://www.filepatio.com/3628
regards
Sharath
I have uploaded a excel fine.I have all data in Sheet 1.I have the search fields in Sheet 2.What i want is when i enter any data in Sheet 2 colum 2.It has to copy the full lines found to a new sheet.
EX:
Say
I put 512 in the Ram box.It has to search the sheet 1 and copy all Rams with 512.
http://www.filepatio.com/3628
regards
Sharath
ASKER
did you check the file i attached.
it is in Excel 2007 format
ASKER
'Check this works fine
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun t
For j = 1 To Sheet1.UsedRange.Columns.C ount
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s 2row + 1)
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun
For j = 1 To Sheet1.UsedRange.Columns.C
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
ASKER
I get this.
-------------------------- -
Microsoft Visual Basic
-------------------------- -
Compile error:
Expected: identifier
-------------------------- -
OK Help
-------------------------- -
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Expected: identifier
--------------------------
OK Help
--------------------------
did u paste this in the sheet2 module?
where r u getting the error in which line
where r u getting the error in which line
ASKER
--------------------------
Microsoft Visual Basic
--------------------------
Compile error:
Only comments may appear after End Sub, End Function, or End Property
--------------------------
OK Help
--------------------------
just delete everytinh in the module and paste this again
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun t
For j = 1 To Sheet1.UsedRange.Columns.C ount
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s 2row + 1)
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun
For j = 1 To Sheet1.UsedRange.Columns.C
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
ASKER
Can you give the macro name too.
'you cannot name this macro because its an event
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun t
For j = 1 To Sheet1.UsedRange.Columns.C ount
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s 2row + 1)
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun
For j = 1 To Sheet1.UsedRange.Columns.C
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=Sheet3.Rows(s
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
ASKER
When i run this it asks me a macro name to run
dont run thiss buddy, just type something in the Sheet2 , e.g 2 GB in RAM and see the results in sheet3
ASKER
Tried this does not work
I should just paste your code in the sheet 2 and type the data you said am i correct?
I did the same but no results.
I should just paste your code in the sheet 2 and type the data you said am i correct?
I did the same but no results.
>I should just paste your code in the sheet 2
no dont paste the code in sheet2,
press Alt + F11 to open the VB Editor , double click Sheet2 on the left pane and on the right paste my code.
then type in sheet2
no dont paste the code in sheet2,
press Alt + F11 to open the VB Editor , double click Sheet2 on the left pane and on the right paste my code.
then type in sheet2
ASKER
Ok got it.Is all the headers linked.When i try for ram,HDD,FDD its working in the machine name when i type it does not how
ASKER
Once i put CDD in the box and i change to DVD the results are not copied.Can you crete new sheets for each search
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
s2row = 1
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets.Add( , ActiveWorkbook.Sheets(Acti veWorkbook .Sheets.Co unt), , xlWorksheet)
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun t
For j = 1 To Sheet1.UsedRange.Columns.C ount
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=sh.Rows(s2row + 1)
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
Static s2row
s2row = 1
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets.Add(
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun
For j = 1 To Sheet1.UsedRange.Columns.C
If Sheet1.Cells(i, j).Value = Target.Value Then
Sheet1.Rows(i).Copy Destination:=sh.Rows(s2row
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
ASKER
Ok great.This is creating a new sheet even when i delete a content in the excel
Can you change the case sensivity
Can you change the case sensivity
Private Sub Worksheet_Change(ByVal Target As Range)
Static s2row
s2row = 1
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets.Add( , ActiveWorkbook.Sheets(Acti veWorkbook .Sheets.Co unt), , xlWorksheet)
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun t
For j = 1 To Sheet1.UsedRange.Columns.C ount
If UCase(Sheet1.Cells(i, j).Value) = UCase(Target.Value) Then
Sheet1.Rows(i).Copy Destination:=sh.Rows(s2row + 1)
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
Static s2row
s2row = 1
Dim sh As Worksheet
Set sh = ActiveWorkbook.Sheets.Add(
If Target <> "" Then
If Target.Column = 2 Then
For i = 1 To Sheet1.UsedRange.Rows.Coun
For j = 1 To Sheet1.UsedRange.Columns.C
If UCase(Sheet1.Cells(i, j).Value) = UCase(Target.Value) Then
Sheet1.Rows(i).Copy Destination:=sh.Rows(s2row
s2row = s2row + 1
End If
Next
Next
End If
End If
End Sub
ASKER
What about the deleting
After i enter fdd and then delete the content.It creates a blank sheet.
After i enter fdd and then delete the content.It creates a blank sheet.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Private Sub Worksheet_Change(ByVal Target As Range)
static s2row
if target.column=2 then
For i=1 to Sheet1.UsedRange.Rows.Coun
For i=1 to Sheet1.UsedRange.Columns.C
if Sheet1.Cells(i,j).value = target.value then
Sheet1.Rows(i).Copy Destination:=Sheet2.Rows(s
s2row=s2row+1
End if
Next
Next
End Sub