Need help for seach marco

Xineq

New Member
Joined
Aug 29, 2014
Messages
34
Hey mr.Excel

I'm trying to make a marco that seach the active sheet for the value of the sheet FAM cell A1. Is this possibel to do??.

Code:
Dim i, lastrow
For i = 1 To lastrow
If ActiveSheet.Cells(i, "G").Value = Worksheets("FAM").Cells(A1).Value Then
    ActiveSheet.Cells(i, "G").EntireRow.Copy Destination:=Sheets("Counting").Range("A" & Rows.Count).End(xlUp).Offset(1)
    End If
Next i

Hoping to can help me see what is wrong with me code
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
First of all, does your code not work?

From what I see, you are searching in column G for the value in sheets FAM cell A1, and on whichever row it is found, it copies that entire row to a sheet named Counting. Is this what you want to achieve?

I know the range.find method might be a better option but i cant say much about which will be more suited to your needs until i have gotten answers to the above questions :)

Victor
 
Upvote 0
My code don't work, i and i dont know why.

Yes i'm searching in column G for the value in sheets FAM cell A1, and on whichever row it is found, it copies that entire row to a sheet named Counting that is correct.

This range.find method you talk about how does that work??
 
Upvote 0
My code don't work, i and i dont know why.

Yes i'm searching in column G for the value in sheets FAM cell A1, and on whichever row it is found, it copies that entire row to a sheet named Counting that is correct.

This range.find method you talk about how does that work??

COlumn G of which sheet?
 
Upvote 0
Give this a try
Rich (BB code):
Sub findcell()
    Dim I As Integer, ws As Worksheet, foundrow As Integer, wks As Worksheet
    Set ws = Worksheets("FAM")
    Set wks = ActiveWorkbook.ActiveSheet
    On Error GoTo errhandler
    foundrow = wks.Range("G:G").Find(ws.Range("a1"), wks.Range("G1")).Row
    Rows(foundrow).EntireRow.Copy Sheets("Counting").Range("A" & Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row)
errhandler:
    MsgBox "Value being sought not found"
End Sub

Or your code slightly modified
Rich (BB code):
Sub Searchcell()
    Dim i, lastrow
    lastrow = ActiveSheet.Range("G" & Rows.Count).End(xlUp).Row
    For i = 1 To lastrow
        If ActiveSheet.Cells(i, "G").Value = Worksheets("FAM").Cells(1, 1).Value Then
            ActiveSheet.Cells(i, "G").EntireRow.Copy Destination:=Sheets("Counting").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End if
    Next i
End Sub

Texts in Red are what i altered
 
Last edited:
Upvote 0
Give this a try
Rich (BB code):
Sub findcell()
    Dim I As Integer, ws As Worksheet, foundrow As Integer, wks As Worksheet
    Set ws = Worksheets("FAM")
    Set wks = ActiveWorkbook.ActiveSheet
    On Error GoTo errhandler
    foundrow = wks.Range("G:G").Find(ws.Range("a1"), wks.Range("G1")).Row
    Rows(foundrow).EntireRow.Copy Sheets("Counting").Range("A" & Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Row)
errhandler:
    MsgBox "Value being sought not found"
End Sub

Or your code slightly modified
Rich (BB code):
Sub Searchcell()
    Dim i, lastrow
    lastrow = ActiveSheet.Range("G" & Rows.Count).End(xlUp).Row
    For i = 1 To lastrow
        If ActiveSheet.Cells(i, "G").Value = Worksheets("FAM").Cells(1, 1).Value Then
            ActiveSheet.Cells(i, "G").EntireRow.Copy Destination:=Sheets("Counting").Range("A" & Rows.Count).End(xlUp).Offset(1)
        End if
    Next i
End Sub

Texts in Red are what i altered

Thanks man trying it out :)
 
Upvote 0
Okay i have tryede them both. the findcell sub only gives me the error msgbox, and ville not print to the Counting sheet. the slightly modified code of my still dont give me a result :S
 
Upvote 0
Interesting, 'cos I tried both codes and they both worked

The findcell will give you that messagebox if no value is found, are you sure the value you seek is in the activesheet and in column G? Does your modified code give any error or it doesnt just work?
 
Upvote 0
Interesting, 'cos I tried both codes and they both worked

The findcell will give you that messagebox if no value is found, are you sure the value you seek is in the activesheet and in column G? Does your modified code give any error or it doesnt just work?

I have tried several different values or names, with no result. The modified code just run it, and gives no output :(
 
Upvote 0

Forum statistics

Threads
1,215,431
Messages
6,124,855
Members
449,194
Latest member
HellScout

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