+ Reply to Thread
Results 1 to 3 of 3

Matching and Cell Referencing

Hybrid View

  1. #1
    Registered User
    Join Date
    04-30-2007
    Location
    JerseyCI/London
    Posts
    35

    Matching and Cell Referencing

    Hi all

    I'm trying to grab data from two sheets by first doing a match.
    The match works, but how can I now reference ws2 so that I can pick up data if this match is true?

    Any help much appreciated

    Danny


    Sub Test_click()
    Dim CurrentWB As Workbook
    Dim Barrister, Barrister2, Box1, Box6, Box4, Box7, ws1, ws2 As String
    Dim rRange, rcell As Range
    
    ws1 = "$Invoices"
    ws2 = "$Summary"
    
    Set CurrentWB = ActiveWorkbook
    
    CurrentWB.Worksheets(ws1).Activate
    
    Set rRange = CurrentWB.Worksheets(ws1).Range("A1", Range("A65536").End(xlUp))
    
    On Error Resume Next
    
    With CurrentWB.Worksheets(ws1)
    For Each rcell In rRange
    
    If rcell = "Barrister" Then GoTo Nrcell
    
    'Grab data from ws1
    Barrister = rcell.Offset(0, 0)
    Box1 = Format(rcell.Offset(0, 12), "#,##0.00")
    Box6 = Format(rcell.Offset(0, 13), "#,##0.00")
    
    'BarrMatch Check
    Barrmatch = Application.Match(Barrister, CurrentWB.Worksheets(ws2).Range("A:A"), 0)
    
            If IsError(Barrmatch) Then
            'Do nothing
            MsgBox "No match"
            Else
            'Match (Normal)
            MsgBox "Barr: " & Barrister & " - Match" & vbNewLine & _
                               "Box1: " & Box1 & vbNewLine & _
                               "Box6: " & Box6
            
            'Grab data from ws2
            'With ws2???
            'Barrister = rcell2.Offset(0, 0)
            'Box4 = Format(rcell2.Offset(0, 11), "#,##0.00")
            'Box7 = Format(rcell2.Offset(0, 12), "#,##0.00")
            
            End If
    Nrcell:
    Next
    End With
    rRange = Nothing
    End Sub
    Last edited by l8sk8r; 06-17-2009 at 11:55 AM.
    /
    ----
    OOO

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: Matching and Cell Referencing

    Use something like

    CurrentWB.Worksheets(ws2).Cells(Barrmatch, "A").Value
    etc.

  3. #3
    Registered User
    Join Date
    04-30-2007
    Location
    JerseyCI/London
    Posts
    35

    Re: Matching and Cell Referencing

    Cheers Bob.

    That will work for the time until I can revise the whole thing.

    Thanks for your help!

    D.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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