VBA code that needs restructuring

Estatefinds

Board Regular
Joined
Sep 14, 2015
Messages
169
I have a code that when run it will search for data from one column and searches for its match in numerous other columns; specifically every 8 columns where data is found and it returns the the row on which that matching data is found.
What i need is for someone to help me change the code so it will search in only one column and return the row it is found on.

(code)
sub my search()
For each gcell in Range("g1", range(G65536").End(xlup))
If isempty(cell(gcell.row, 8)) Then
For each c in Range ("Z1:AOOO324597")
I=Application.match(gcell.value, Range(c, Cells(324597, c.column)), 0)
if Not iserror(I) Then
Cells(gcell.row,8)=I
exit for
end if
next
if is empty(cells(gcell.row, 8)) then
cells(gcell.row, 8) ="$#N/A"
end if
end if
next
end sub
 
so What I am try to accomplish is instead of searching through the Z1 to AOO324597 the code will only search in the Z column. so Z1 through Z324597
 
Last edited:
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
so What I am try to accomplish is instead of searching through the Z1 to AOO324597 the code will only search in the Z column. so Z1 through Z324597. so the code looks at column "G" then looks for the Matching data in column "Z" then it returns the row that the matching data was found within column Z.
 
Upvote 0
so What I am try to accomplish is instead of searching through the Z1 to AOO324597 the code will only search in the Z column. so Z1 through Z324597. so the code looks at column "G" then looks for the Matching data in column "Z" then it returns the row that the matching data was found within column Z.
 
Upvote 0
Don't have Excel at the moment....and still don't follow your code....but is this what you want...UNTESTED
Code:
Sub mysearch()
Dim lr As Long, c As Range
lr = Cells(Rows.Count, "G").End(xlUp).Row
For Each c In Range("G1:G" & lr)
If c.Value = "" Then c.Value = "#N/A"
I = Application.Match(c.Value, Range("Z1:Z" & lr), 0)
If Not IsError(I) Then c.Value = I
Next c
End Sub
 
Upvote 0
This code didn't work but I'll give an idea how the excel is set up.
Column G has numerical data. Column H is where the row is recorded, based on where each matching data is found on column Z. So the code will return the row on which data found on to column H and it will say "done" in column I. The original code would do a search every 8 columns where data was found but I placed it in one column for organization purposes and easier reading
 
Upvote 0
Try this:
Code:
Sub mysearch()
    Dim lr As Long
    Dim i As Long
    lr = Cells(Rows.Count, 7).End(xlUp).Row
    For i = 2 To lr
        If Not Cells(i, 7).Value = "" Then
            On Error Resume Next
            Cells(i, 8).Value = Columns(26).Find(What:=Cells(i, 7).Value, After:=Columns(26).Cells(1, 1), _
                LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=True).Row
            On Error GoTo 0
            If Cells(i, 8).Value = "" Then Cells(i, 8).Value = "Not Found"
        End If
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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