Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA VLookup or equivalent

I've spent a couple of hours trawling the groups for an answer, so apologies
if it's there and I missed it.

I have an employee number in column b in a file named test, I want to lookup
the employee number in a file called nominal (column b) and return the
person's surname (column e) to column c in the file named test.

I'm trying to use VBA to achieve this as there are 31 sheets in the test
file, the data is entered each day and I don't want the users having to copy
and paste / drag formulas down.

I'm more than a little rusty as I'm returning to code after 5 years! Any
and all help greatly appreciated.

Jude
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default VBA VLookup or equivalent

I think you should put all the data together in a single worksheet, instead
of having 31 worksheets. Suppose wks32 contains all the data, then you could
use the VLOOKUP function as usual. The following macro is a bit long, but I
think it will help you to get started.

Option Explicit
Public Sub subCopyWks()
Dim wbk As Workbook
Dim wks As Worksheet
Dim SourceRange As Range
Dim DestRange As Range
Dim i As Long

'Initialize wbk
Set wbk = ActiveWorkbook

'Initialize the destination worksheet
'Suppose the name of this worksheet that contains all
'data is wks32.
Set wks = wbk.Worksheets("wks32")

For i = 0 To 31
'Get the data from the source worksheet
With wbk.Worksheets(i + 1)
'Initialize the range that contains the data
'Suppose it goes from cell A1 to cell B10 in each worksheet
Set SourceRange = .Range(.Cells(1, 1), .Cells(10, 2))
End With
'Copy the data
SourceRange.Copy
'Initialize the destination range
With wks
Set DestRange = .Range(.Cells(i * 10 + 1, 1), .Cells((i + 1) * 10, 2))
End With
'Paste the data
'This command has several options that you should check
DestRange.PasteSpecial
Next i

'Clean
Set wbk = Nothing
Set wks = Nothing
Set SourceRange = Nothing
Set DestRange = Nothing
End Sub


--
Carlos


"MuppetBaby" wrote:

I've spent a couple of hours trawling the groups for an answer, so apologies
if it's there and I missed it.

I have an employee number in column b in a file named test, I want to lookup
the employee number in a file called nominal (column b) and return the
person's surname (column e) to column c in the file named test.

I'm trying to use VBA to achieve this as there are 31 sheets in the test
file, the data is entered each day and I don't want the users having to copy
and paste / drag formulas down.

I'm more than a little rusty as I'm returning to code after 5 years! Any
and all help greatly appreciated.

Jude

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default VBA VLookup or equivalent

Hi Carlos,

Thanks for your reply, but I'm not sure it resolves my issue. There are 31
worksheets because it's a daily overtime form, it calculates how many hours
each person has worked, what rate of pay they should be paid and whether they
are entitled to time off in lieu. The user specifically requested that there
is a tab for each day of the month. Also, the nominal file is a download
from Oracle HR. I wanted to use it in it's raw form rather than having to
copy and paste if possible.

Thanks

Jude
"Carlos" wrote:

I think you should put all the data together in a single worksheet, instead
of having 31 worksheets. Suppose wks32 contains all the data, then you could
use the VLOOKUP function as usual. The following macro is a bit long, but I
think it will help you to get started.

Option Explicit
Public Sub subCopyWks()
Dim wbk As Workbook
Dim wks As Worksheet
Dim SourceRange As Range
Dim DestRange As Range
Dim i As Long

'Initialize wbk
Set wbk = ActiveWorkbook

'Initialize the destination worksheet
'Suppose the name of this worksheet that contains all
'data is wks32.
Set wks = wbk.Worksheets("wks32")

For i = 0 To 31
'Get the data from the source worksheet
With wbk.Worksheets(i + 1)
'Initialize the range that contains the data
'Suppose it goes from cell A1 to cell B10 in each worksheet
Set SourceRange = .Range(.Cells(1, 1), .Cells(10, 2))
End With
'Copy the data
SourceRange.Copy
'Initialize the destination range
With wks
Set DestRange = .Range(.Cells(i * 10 + 1, 1), .Cells((i + 1) * 10, 2))
End With
'Paste the data
'This command has several options that you should check
DestRange.PasteSpecial
Next i

'Clean
Set wbk = Nothing
Set wks = Nothing
Set SourceRange = Nothing
Set DestRange = Nothing
End Sub


--
Carlos


"MuppetBaby" wrote:

I've spent a couple of hours trawling the groups for an answer, so apologies
if it's there and I missed it.

I have an employee number in column b in a file named test, I want to lookup
the employee number in a file called nominal (column b) and return the
person's surname (column e) to column c in the file named test.

I'm trying to use VBA to achieve this as there are 31 sheets in the test
file, the data is entered each day and I don't want the users having to copy
and paste / drag formulas down.

I'm more than a little rusty as I'm returning to code after 5 years! Any
and all help greatly appreciated.

Jude

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
Equivalent of Vlookup function programmatically [email protected] Excel Programming 3 January 3rd 07 03:49 PM
How do I create an equivalent VLOOKUP function using FIND? dan Excel Worksheet Functions 8 August 17th 05 04:43 PM
VBA equivalent of VLookup on an array KR Excel Programming 0 March 21st 05 05:39 PM
searching for vlookup equivalent in VBA Tom Ogilvy Excel Programming 0 August 31st 04 06:20 PM
VB's equivalent to VLOOKUP? Dan Excel Programming 4 June 9th 04 08:47 PM


All times are GMT +1. The time now is 08:53 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"