Results 1 to 1 of 1

vlookup in a VBA code?

Threaded View

  1. #1
    Forum Contributor
    Join Date
    12-27-2007
    Posts
    106

    vlookup in a VBA code?

    Hi

    I've got the following code:

    Option Explicit
    
    Private Sub Worksheet_Change(ByVal Target As Range)
    
        With Target
            If .Column = 1 Then
                .Offset(, 1) = Now
                .Offset(, 2) = "1"
        
            Dim Cell As Range
            For Each Cell In Target
                If Cell.Column = 1 Then
                    If Application.CountIf(Columns(7), Cell) = 0 Then
                        Cells(Cells.Rows.Count, 7).End(xlUp).Offset(1, 0) = Cell
                        Cells(Cells.Rows.Count, 7).End(xlUp).Offset(0, 1).FormulaR1C1 = "=SUMIF(C[-7],RC[-1],C[-5])"
                    End If
                End If
            Next Cell
            End If
         End With
    End Sub
    Plus the follwing vlookup function:

    PHP Code: 
    =VLOOKUP(G2,'REF PAGE'!$A$1:$L$997,2,FALSE
    What this does is to:
    1. enter barcode into col a
    2. Automatically enters todays date in col b
    3. pops up inpt box and asks for quantity, which is then put into col c
    4. barcode is automatically entered in col G
    5. total of the quatities for the barcode are automatically calculated in col H
    6. Col I: looks up barcode from col G, from another worksheet called "ref page", and inserts the value from the second column (i.e. col B) of the "ref page" worksheet

    The trouble is that i have to copy the vlookup formula all the way to the end of the column for this to work - so i was hoping that if using VBA, perhaps the vlookup function could be incorporated into the VBA - thus excel will automatically do the vlookup when Col G is populated - is thsi possible?

    Also, is it possible for the data located in Col G and H to be automatically copied to a completely new sheet?
    Last edited by tony0710; 03-03-2009 at 04:02 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1