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

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I have uploaded a test sheet here https://www.dropbox.com/s/i59qsvqt1bnb36v/ForTest.xlsm?dl=0

The value in FAM!A1 is Jane, Run the code and see if the row from Sheet6 is copied to the counting sheet(that should be row 9)

I guess the you always set the sheet you want to run the code on as the active sheet before running the code

Okay this is abit wierd your code is working perfectly, and also the modified one to. I have also tried setting up a new doc for some testing and it works there to getting abit pissed :/
 
Upvote 0
Fair enough.

So the culprit is your workbook right? Well, that takes us one step closer to the solution :) or so i think
 
Upvote 0
Okay i got it to work, bye restarting excel and transfer my data to a new master dok. I think it was the workbook that was bugged or somthing, anyway thanks alot for the help really made my work lot alot esayer
 
Upvote 0
How bout this version?

Code:
Sub findcell()
    Dim i As Integer, FAM As Worksheet, LastRow As Integer, ActSht As Worksheet, NRow As Integer
    Dim Fi As String
 On Error GoTo errhandler
    Set FAM = Sheets("FAM")
    Set ActSht = ActiveWorkbook.ActiveSheet
    
    Fi = FAM.Cells(1, 1).Value
    
    LastRow = ActSht.Cells(Rows.Count, 7).End(xlUp).Row + 1
    For i = 1 To LastRow
       If Cells(i, 7).Value = Fi Then
       NRow = Sheets("Counting").Cells(Rows.Count, 7).End(xlUp).Offset(1, 0).Row
        Sheets("Counting").Rows(NRow).Value = Rows(i).Value
       End If
    Next
Exit Sub
    
errhandler:
    MsgBox "Error occurred"
End Sub
 
Upvote 0
@Arithos Thanks anyway man, maybe i'm going to be able to use your code anyway :)

Glad to help, This way of coding is, for me, very easy to understand (logical even! :P). And similar ways of sorting/moving data using this approach is easy to build up, and understand. ;)
 
Upvote 0

Forum statistics

Threads
1,216,079
Messages
6,128,687
Members
449,464
Latest member
againofsoul

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