Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default help with vlookup or similar

This doesn't look like a job for =vlookup() to me.

And since you want to return the cell to the left, you're really looking at
B1:F100, right. If you find Dog in column A, then there's nothing to the left
to bring back.

And do you really mean that you only want to bring back the match for A1?

Option Explicit
Sub testme02()

Dim ActWks As Worksheet
Dim SearchWks As Worksheet
Dim RngToSearch As Range
Dim FoundCell As Range
Dim myRng As Range
Dim myCell As Range

Set ActWks = Worksheets("Sheet1")
Set SearchWks = Worksheets("sheet2")

With ActWks
Set myRng = .Range("a1")
'or for all the used cells in column A
'Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With SearchWks
Set RngToSearch = .Range("b1:F100")
End With

For Each myCell In myRng.Cells
With RngToSearch
Set FoundCell = .Cells.Find(what:=myCell.Value, _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
lookat:=xlWhole, _
searchorder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)
End With

If FoundCell Is Nothing Then
'not found???
'give a message or just leave it alone?
myCell.Offset(0, 1).Value = "Not Found!"
Else
myCell.Offset(0, 1).Value = FoundCell.Offset(0, -1).Value
End If
Next myCell

End Sub

I used lookat:=xlwhole and matchcase:=false. You may not want those.

keri wrote:

Hi,

I've been through lots of old posts but cannot seem to make anything
work.

I need to populate column B on sheet 1 with values from columns A:F on
sheet 2, based on the value in column A sheet 1

For example if on sheet1!A1 the value was "dog" I need to have vba
code to find ""dog anywhere in sheet2!a1:f100 and return the value one
column to the left of where it is found into sheet1!b1

This needs to be done in code. Many thanks,


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Vlookup help ... or something similar Bud Excel Worksheet Functions 8 June 30th 06 10:07 PM
vlookup or similar help Ash Excel Worksheet Functions 1 May 26th 06 06:17 AM
Similar to Vlookup Mike Excel Discussion (Misc queries) 1 February 1st 06 04:21 PM
Similar to VLOOKUP? Harish Mohanbabu[_3_] Excel Programming 3 December 3rd 05 03:13 AM
Help w/ Vlookup or similar Gmet Excel Programming 1 September 6th 04 02:56 PM


All times are GMT +1. The time now is 07:54 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"