Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use VB code to define vlookup in two workbook


Dear friends,

I try to combine data between two worksheet using VB. One workbook
calls SAN kept in c:\test\import, another workbook calls WYE kept in
c:\test\backup

SAN Workbook has one sheet (sheet1)
COLUMN A B
C034001
C042001
C054021

WYE Workbook has one sheet(code)
column A B
C034001 WYE1
C042001 WYE2
C054021 WYE3


Now want to use vb code to copy WYE column B value to SAN column B
based on the column A. But always failed. Could anybody help me. Thanks
so much

My current some code as below
set backxl=new excel.application
set destxl=new excel.applicaiton

strDestF=C:\test\import\san.xls
strBackF=c:\test\backup\wye.xls
destXL.Workbooks.Open strDestF
backXL.Workbooks.Open strBackF
i=0


I try to use vlookup to get value from wye.xls to san.xls, but failed
destXL.Cell(i + 2, 2) = "vlookup('" & destXL.Cells(i + 2, 1) & "'," &
"[strBackF]Code!A$A$2" & ":" & "$B$4" & ",2)"

Regards


--
yihong
------------------------------------------------------------------------
yihong's Profile: http://www.excelforum.com/member.php...o&userid=25018
View this thread: http://www.excelforum.com/showthread...hreadid=385473

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use VB code to define vlookup in two workbook


how about using find command to get the row and just refer to the cell
column and row?

the below is an example

tender = Sheets("km").Cells(j, colkm).Text
Set rng = Sheets("nominated").Range("nom").Find(tender)
If rng Is Nothing Then GoTo badkmtender
nomrow = rng.Row


--
duane


------------------------------------------------------------------------
duane's Profile: http://www.excelforum.com/member.php...o&userid=11624
View this thread: http://www.excelforum.com/showthread...hreadid=385473

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use VB code to define vlookup in two workbook


Hi, Duane

Thanks for your reply. Because wye.xls has many codes. A is our company
code, B is our customer code. So use Vlookup I think is the fastest way
to get the customer code from WYE.xls and paste to SAN.XLS.

Regards


--
yihong
------------------------------------------------------------------------
yihong's Profile: http://www.excelforum.com/member.php...o&userid=25018
View this thread: http://www.excelforum.com/showthread...hreadid=385473

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default how to use VB code to define vlookup in two workbook


Dear friends,

I used VB (excel.application) to open two excel file (One called
AAA.XLS is standard code, another called BBB.XLS will get code from
AAA.XLS), after finishing, I use .Quit to exit both of excel file. Then
again to open another excel file CCC.XLS to get AAA.XLS code, but
failed. I suspected excel or workbook or temp file didn't acutually
close. Below is part of my codeing, when second time run to
destXL.Cells(iRowDest, 31) = Application.VLookup(findString, rang1, 2,
False), will failed. Here destxl is the example BBB.XLS or CCC.XLS,
backxl likes AAA.XLS.
I tried many times, but all failed. Anyone can help. Thanks so much!

Set backXL = New excel.Application 'SANKYU AND WYETH CODE
Set destXL = New excel.Application 'NEED ADD WYETH CODE

destXL.Workbooks.Open strDestF
destXL.Cells(1, 31) = "WYETH"

backXL.Workbooks.Open strBackF
'Do While backXL.Cells(backCount, 1) < ""
' backCount = backCount + 1 'get how many wyeth code in template
'Loop

'
Do While destXL.Cells(iRowDest, 30) < ""
Dim findString As String
Dim rang1 As Range

Set rang1 = backXL.Range("A2:B10000")
findString = destXL.Cells(iRowDest, 30)
destXL.Cells(iRowDest, 31) = Application.VLookup(findString, rang1,
2, False)

iRowDest = iRowDest + 1
sourceCount = iRowDest

Loop
destXL.Cells(sourceCount, 25) = "=SUM(Y2:Y" & sourceCount - 1 & ")"
lbxFile.Refresh
Kill (strSourceF)
MsgBox "Finish to add Wyeth Code!", vbOKOnly, "Finish"
'clean up and exit
Set oWS = Nothing
If Not oWB Is Nothing Then oWB.Close
Set oWB = Nothing
destXL.Quit
backXL.Quit
'Kill (strBackF)
btnExport.Enabled = False
Set destXL = Nothing
Set backXL = Nothing
Application.Quit
btnExport.Enabled = False
btnConfirm.Enabled = False
excel.Application.Quit
'Application.ActiveWindow.Close
'Unload Me
Exit Sub


--
yihong
------------------------------------------------------------------------
yihong's Profile: http://www.excelforum.com/member.php...o&userid=25018
View this thread: http://www.excelforum.com/showthread...hreadid=385473

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 VBA Code to Let User Define Active Sheet zulfer7 Excel Discussion (Misc queries) 3 March 29th 07 02:59 PM
Looking for code to define a range Ant Excel Discussion (Misc queries) 3 October 3rd 05 06:22 PM
Delete Define names across workbook Mike Excel Worksheet Functions 4 September 28th 05 12:41 AM
How do I define a macro that will generate VBA code? I believe Excel Programming 1 May 16th 05 04:12 PM
VBA code to define nbr of text character a a cell/column James[_35_] Excel Programming 0 March 18th 05 05:52 PM


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