Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Help on Vlookup for Undetermined Range

Am new on macros and need assistance to adjust the macro below for
undetermined ranges

Dim rng As Range
Dim i As Integer

With Worksheets("sheet1")
Set rng = .Range("a2:b8")
End With

For i = 1 To 7
With Worksheets("sheet2") 'assuming the data you want goes to column b
and
'the lookup value is in Column A'
..Cells(1 + i, 2) = Application.WorksheetFunction.VLookup(.Cells(1 + i,
1), rng, 2, 1)
End With

Next i

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Help on Vlookup for Undetermined Range

what does this code do?
what do you want it to do?
what do you mean by undetermined range?

"sylink" wrote:

Am new on macros and need assistance to adjust the macro below for
undetermined ranges

Dim rng As Range
Dim i As Integer

With Worksheets("sheet1")
Set rng = .Range("a2:b8")
End With

For i = 1 To 7
With Worksheets("sheet2") 'assuming the data you want goes to column b
and
'the lookup value is in Column A'
..Cells(1 + i, 2) = Application.WorksheetFunction.VLookup(.Cells(1 + i,
1), rng, 2, 1)
End With

Next i


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Help on Vlookup for Undetermined Range

I need to compare the sheet1 and sheet2 and fill the date values in
sheet1 . The range is undetermined in that the no of row in both sheet1
and sheet2 is not known.


sheet1 sheet2
Names Date Names
Date
===== ====
AAICDLTD AAICDLTD
11-Jan-01
ABALUF ABANITO
27-Jul-01
ABIMACJ ABALUF
28-Aug-02
ADESEUN ABIMACJ
19-Nov-01
ADESEUN
12-Dec-02
Some suggested the code below, but would not work for an unknown no of
rows.

Sub Button1_Click() Dim rng As Range Dim i As Integer With
Worksheets("Data") Set rng = .Range("a3:b5") 'make as long as you need
End With For i = 1 To 3 ' how ever many cells there are With
Worksheets("Results") 'assuming the data you want goes to column b and
the lookup value is in Column A' .Cells(2 + i, 2) =
Application.WorksheetFunction.VLookup(.Cells(2 + i, 1), rng, 2, 1) End
With Next i End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 279
Default Help on Vlookup for Undetermined Range

OK I might understand the question.

You do not know the number of rows of information in Sheet 1

One way to loop through is:

Dim myCell as Range

With Activeworkbook.Sheets('Data")

For Each myCell in .Range(.Cells(3,1),.Cells(60000,1).End(XLUp))
'''your search code here using myCell as the cell.value you are looking up
next myCell

End With


"sylink" wrote:

I need to compare the sheet1 and sheet2 and fill the date values in
sheet1 . The range is undetermined in that the no of row in both sheet1
and sheet2 is not known.


sheet1 sheet2
Names Date Names
Date
===== ====
AAICDLTD AAICDLTD
11-Jan-01
ABALUF ABANITO
27-Jul-01
ABIMACJ ABALUF
28-Aug-02
ADESEUN ABIMACJ
19-Nov-01
ADESEUN
12-Dec-02
Some suggested the code below, but would not work for an unknown no of
rows.

Sub Button1_Click() Dim rng As Range Dim i As Integer With
Worksheets("Data") Set rng = .Range("a3:b5") 'make as long as you need
End With For i = 1 To 3 ' how ever many cells there are With
Worksheets("Results") 'assuming the data you want goes to column b and
the lookup value is in Column A' .Cells(2 + i, 2) =
Application.WorksheetFunction.VLookup(.Cells(2 + i, 1), rng, 2, 1) End
With Next i End Sub


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
vlookup more than 2 range hitesh Excel Discussion (Misc queries) 5 May 30th 08 09:30 PM
Using VLOOKUP with a 3D range Cassie Excel Worksheet Functions 4 September 11th 07 11:29 PM
Summing values from an undetermined number of sheet smaruzzi Excel Worksheet Functions 3 April 6th 07 08:16 PM
Vlookup where range changes Greg Excel Worksheet Functions 1 March 17th 06 11:41 PM
Summing undetermined colums RJH Excel Programming 7 December 23rd 03 07:01 PM


All times are GMT +1. The time now is 03:46 AM.

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"