search for text in range returns "1004" in msgbox

tomleitch

Board Regular
Joined
Jan 3, 2012
Messages
189
Hi all,

I'm trying to put some code together that looks for a text match in the top row of titles of a sheet...

What I want to do is find the column that contains the text "Description" and copy the whole column into a specified column on another sheet.


I have some code that looks at the last row in the A column to find the bottom of the range but what I'm struggling with is to find the other part - I set a msgbox to tell me what the value is but it's just giving me 1004


This is an excerpt from the code: (I've got the lcol bit all sorted to give me the end column of the data)


Code:
Dim rng As Range
Dim Description As Variant
Dim rowNum As Long

    Set rng = Sheets("UPDATE TOOL").Range("A1" & "A" & lcol)
    
    Description = "Description"
    If Not IsError(Application.Match(aNumber, rng, 0)) Then
        rowNum = Application.Match(aNumber, rng, 0)
        MsgBox rowNum
    Else
        If MsgBox("Description not found", vbOKCancel) = vbCancel Then GoTo 100
            
        
    End If



I'm sure it's something fairly simple! Any help appreciated.

Thanks
Tom
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Are you trying to find the word in row1?
If so use
Code:
Set rng = Sheets("UPDATE TOOL").Range("A1", Sheets("UPDATE TOOL").Cells(1, lcol))
Also what is "aNumber"? Should that be Description?
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

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