Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / September 2007

Tip: Looking for answers? Try searching our database.

VBA VLookup or equivalent

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MuppetBaby - 25 Sep 2007 19:02 GMT
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
Carlos - 25 Sep 2007 19:56 GMT
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

Signature

Carlos

> I've spent a couple of hours trawling the groups for an answer, so apologies
> if it's there and I missed it.
[quoted text clipped - 11 lines]
>
> Jude
MuppetBaby - 26 Sep 2007 07:04 GMT
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

> 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
[quoted text clipped - 57 lines]
> >
> > Jude
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.