Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual basic - VLOOKUP

Status
Not open for further replies.

Evening

Technical User
Jan 19, 2005
45
0
0
CA
Can someone help me how to do this. I started something but cant figure out myself 100%.

In have in SHT-1 columns A & B, C D, .
Column A-
B-Ident Number
C-Description …
D- ..

In SHT-2 I have :

A - ..
B -
C- Ident Number
D-
E-
F- Description


I want periodically to update in SHT-1 the column C-Description based on the Ident Number from the SHT-2. the second SHT-2 doesn’t contain all Ident numbers what SHT-1 has.

I’d like to put in SHT-1 in temporary unused column X all values: VLOOKUP(B1, SHT-2!C100:F1000, 4, FALSE)

If the Ident number was found , copy to column C, and if it wasn’t found in SHT-2, just to leave same field value what was already there in SHT-1.

So, I really don’t use the formula in spreadsheet in SHT-1, the cell B is not protected in SHT-1.

VSB program in SHT-1:


lastRowColA = Range("A65536").End(xlUp).Row
counter = 0
Do While counter < lastRowColA
counter = counter + 1
Range("X" & counter).Select
‘ Vlookup(B1, Sht-2!C10:F1000, 4, False) I am not sure about syntax right)’
‘ Enter the value in field X’
‘ IF the value in sht-was found,
copy the X field in C field ‘
ELSE
Don’t do anything , go to next field
Endif
Loop


What would be the real code for this?
 


Hi,
Code:
    Dim x
    
    lastRowColA = Range("A65536").End(xlUp).Row
    counter = 0
    Do While counter < lastRowColA
          counter = counter + 1

          x = Application.VLookup(Range("B1"), Sheets("Sht-2").Range("C10:F1000"), 4, False)
          
          If Not IsError(x) Then
            Cells(counter, "X").Value = x
          End If
    Loop

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top