PDA

View Full Version : vlookup to include second worksheet - in vba code



Pete
09-10-2008, 01:39 AM
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

Bob Phillips
09-10-2008, 02:09 AM
Worksheets aren't open, they can be actve but not open. ANd only one worksheet in a workbook can be active at a time.

Pete
09-10-2008, 02:12 AM
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....

Bob Phillips
09-10-2008, 02:19 AM
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.

Pete
09-10-2008, 02:24 AM
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"