Consulting

Results 1 to 5 of 5

Thread: vlookup to include second worksheet - in vba code

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location

    vlookup to include second worksheet - in vba code

    Hi Experts

    The following attached snippet code looks up the data in column N worksheet "New Business" and paste it into column N the worksheet "Scenario 1".....which works fine when the user click the RESET macro button in worksheet "Scenario 1"...

    however, here is the question.

    I would lke to amend the vba code so that if any one of the following worksheet(s) "Previous Terms" or "New Business" is open in the workbook it works...Point. only one worksheet either "Previous Terms" or "New Business" can be open at any one time....
    both cannot be open at the same time....

    Public Sub Reset()

    With Sheets("Scenario1")
    Application.Calculation = xlCalculationManual
    Dim rng As Range

    Set rng = Range(.Cells(10, 14), .Cells(Rows.Count, 14).End(xlUp))
    Dim c As Range
    For Each c In rng.Cells
    c = WorksheetFunction.VLookup(c.Offset(0, -12), Excel.Range("'New Business'!" & Range(Sheets("New Business").Cells(10, 2).Address, Sheets("New Business").Cells(Rows.Count, 14).End(xlUp).Address).Address), 13, False)
    c.Font.Bold = False
    c.Font.Color = 0
    Next c

    .Range("U2").Select
    Application.Calculation = xlCalculationAutomatic
    End With

    End Sub

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Worksheets aren't open, they can be actve but not open. ANd only one worksheet in a workbook can be active at a time.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    ok if i could up load the file is you would understand but do to file size restriction on this site i cannot.....

    What i am saying is that depending on what the users select, only one of the worksheet(s) "Previous Terms" or "New Business" is open.

    So if the user select from the Intro Worksheet "New Business" then worksheet new business is open and if the user likewise selects from the intro worksheet "re-negiotation" the Previous Terms worksheet is open in the workbook....

    so hence only one of the mentioned worksheets is open at any given time.........

    i hope this helps....

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    No, it doesn't help because you keep saying worksheet ... open, and you don't open worksheets. As I said, if you mean active, only one can be active anyway, so the question makes no sense.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Activite thats what i mean only one worksheet can be acitvit at any given time in the workbook. Apologies, if i am using the wrong/incorrect terms...

    and the worksheets are "New Business" and "Previous Terms"

Posting Permissions

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