Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default vlookup code and accumulate - sorry need help

dear all/frank,
i am so sorry need to bug you all but i really hope can have the help
from here.
i do not know why my vlookup cannot work in vba. if i type in the
sheet as below can work nicely. pls help.

this can work.... but i cannot ask user to do this...
=IF(B15<"",IF(ISNA(VLOOKUP("*"&B15&"*",Sheet4!$A$ 2:$B$300,2,FALSE)),"Item
Not Found In COA",VLOOKUP("*"&B15&"*",Sheet4!$A$2:$B$300,2,FALS E)),"")



this cannot work..... always return 21000 and also cannot return value
in current sheet. z cannot assign value to cell. nothing show

Private Sub CommandButton1_Click()
Dim i As Long

Set TableA = Range("B15:B168")
Set tableB = Sheet4.Range("$A$2:$B$300")

'Set tableb = Range("Sheet4!$A$2:$B$300")
X = TableA.Cells(i, "B").Value
'Z = TableA.Cells(i, "U").Value
z = TableA.Cells(i, "U")


For i = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value = " " Then
' accumulate amount in TableB
Else
y = Application.VLookup("*" & X & "*", tableB, 2, False)
z = y 'put code in TableA
End If
Next i

sheet1

desc cannot update fr sheet4 accumulate and put other
sheet by item
HEMI HEAD Item Not Found In COA 383695.49

SHELL PLATE 21110 1653551.84
SHELL PLATE 21110 319919.90
SHELL PLATE 21110 59204.15

STIFFERNER RING Item Not Found In COA 164021.43
ELLIPSOIDAL HEAD Item Not Found In COA 4887.35

SHELL PLATE 21110 9945.34



sheet4 A2:B300
Description Cost Code
PROCUMENT DEPARTMENT COST 21000
CARBON STEEL 21100
CARBON STEEL - SHELL PLATE 21110
CARBON STEEL - HEADS 21120
CARBON STEEL - SKIRTS/SAD 21130
CARBON STEEL - PIPES 21140
CARBON STEEL - FITTINGS 21150
CARBON STEEL - VALVE 21160
CARBON STEEL - TUBE SHEET 21170
CARBON STEEL - TUBES/U-TU 21180
CARBON STEEL - FLANGES/FO 21190
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 618
Default vlookup code and accumulate - sorry need help

Hi Tango

You might like to change

Application.VLookup
to
Application.WorksheetFunction.VLookup
and see if that solves your problem

Cheers
JulieD

"tango" wrote in message
om...
dear all/frank,
i am so sorry need to bug you all but i really hope can have the help
from here.
i do not know why my vlookup cannot work in vba. if i type in the
sheet as below can work nicely. pls help.

this can work.... but i cannot ask user to do this...
=IF(B15<"",IF(ISNA(VLOOKUP("*"&B15&"*",Sheet4!$A$ 2:$B$300,2,FALSE)),"Item
Not Found In COA",VLOOKUP("*"&B15&"*",Sheet4!$A$2:$B$300,2,FALS E)),"")



this cannot work..... always return 21000 and also cannot return value
in current sheet. z cannot assign value to cell. nothing show

Private Sub CommandButton1_Click()
Dim i As Long

Set TableA = Range("B15:B168")
Set tableB = Sheet4.Range("$A$2:$B$300")

'Set tableb = Range("Sheet4!$A$2:$B$300")
X = TableA.Cells(i, "B").Value
'Z = TableA.Cells(i, "U").Value
z = TableA.Cells(i, "U")


For i = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value = " " Then
' accumulate amount in TableB
Else
y = Application.VLookup("*" & X & "*", tableB, 2, False)
z = y 'put code in TableA
End If
Next i

sheet1

desc cannot update fr sheet4 accumulate and put other
sheet by item
HEMI HEAD Item Not Found In COA 383695.49

SHELL PLATE 21110 1653551.84
SHELL PLATE 21110 319919.90
SHELL PLATE 21110 59204.15

STIFFERNER RING Item Not Found In COA 164021.43
ELLIPSOIDAL HEAD Item Not Found In COA 4887.35

SHELL PLATE 21110 9945.34



sheet4 A2:B300
Description Cost Code
PROCUMENT DEPARTMENT COST 21000
CARBON STEEL 21100
CARBON STEEL - SHELL PLATE 21110
CARBON STEEL - HEADS 21120
CARBON STEEL - SKIRTS/SAD 21130
CARBON STEEL - PIPES 21140
CARBON STEEL - FITTINGS 21150
CARBON STEEL - VALVE 21160
CARBON STEEL - TUBE SHEET 21170
CARBON STEEL - TUBES/U-TU 21180
CARBON STEEL - FLANGES/FO 21190



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default vlookup code and accumulate - sorry need help

Hi
without testing it try changing the following:

Private Sub CommandButton1_Click()
Dim i As Long
dim z as range
dim tableA as range
Dim tableB as range
Dim y

Set TableA = Range("B15:B168")
Set tableB = Sheet4.Range("$A$2:$B$300")

'Set tableb = Range("Sheet4!$A$2:$B$300")
X = TableA.Cells(i, "B").Value
'Z = TableA.Cells(i, "U").Value

For i = 15 To Cells(Rows.Count, "B").End(xlUp).Row
set z = TableA.Cells(i, "U")
If Cells(i, "B").Value = "" Then
' accumulate amount in TableB
Else
y = Application.VLookup("*" & X & "*", tableB, 2, False)
z.value = y 'put code in TableA
End If
Next i




"tango" wrote:

dear all/frank,
i am so sorry need to bug you all but i really hope can have the help
from here.
i do not know why my vlookup cannot work in vba. if i type in the
sheet as below can work nicely. pls help.

this can work.... but i cannot ask user to do this...
=IF(B15<"",IF(ISNA(VLOOKUP("*"&B15&"*",Sheet4!$A$ 2:$B$300,2,FALSE)),"Item
Not Found In COA",VLOOKUP("*"&B15&"*",Sheet4!$A$2:$B$300,2,FALS E)),"")



this cannot work..... always return 21000 and also cannot return value
in current sheet. z cannot assign value to cell. nothing show

Private Sub CommandButton1_Click()
Dim i As Long

Set TableA = Range("B15:B168")
Set tableB = Sheet4.Range("$A$2:$B$300")

'Set tableb = Range("Sheet4!$A$2:$B$300")
X = TableA.Cells(i, "B").Value
'Z = TableA.Cells(i, "U").Value
z = TableA.Cells(i, "U")


For i = 15 To Cells(Rows.Count, "B").End(xlUp).Row
If Cells(i, "B").Value = " " Then
' accumulate amount in TableB
Else
y = Application.VLookup("*" & X & "*", tableB, 2, False)
z = y 'put code in TableA
End If
Next i

sheet1

desc cannot update fr sheet4 accumulate and put other
sheet by item
HEMI HEAD Item Not Found In COA 383695.49

SHELL PLATE 21110 1653551.84
SHELL PLATE 21110 319919.90
SHELL PLATE 21110 59204.15

STIFFERNER RING Item Not Found In COA 164021.43
ELLIPSOIDAL HEAD Item Not Found In COA 4887.35

SHELL PLATE 21110 9945.34



sheet4 A2:B300
Description Cost Code
PROCUMENT DEPARTMENT COST 21000
CARBON STEEL 21100
CARBON STEEL - SHELL PLATE 21110
CARBON STEEL - HEADS 21120
CARBON STEEL - SKIRTS/SAD 21130
CARBON STEEL - PIPES 21140
CARBON STEEL - FITTINGS 21150
CARBON STEEL - VALVE 21160
CARBON STEEL - TUBE SHEET 21170
CARBON STEEL - TUBES/U-TU 21180
CARBON STEEL - FLANGES/FO 21190

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
Accumulate values jk Setting up and Configuration of Excel 3 August 3rd 06 06:25 PM
accumulate exhausted everything Excel Discussion (Misc queries) 1 March 15th 06 03:24 AM
accumulate totals exhausted everything Excel Worksheet Functions 1 March 14th 06 11:30 PM
how to accumulate value and put in other sheet mango Excel Worksheet Functions 7 October 29th 04 08:42 AM
how to accumulate value and put in other sheet tango Excel Programming 1 October 29th 04 06:36 AM


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

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

About Us

"It's about Microsoft Excel"