PDA

View Full Version : Open 2 worksheet at the same time



alexandro88
11-05-2011, 10:19 AM
lr_Total = FormatPercent((lr1 / (lr1 + lr2)), 4)

Worksheets("LW").Activate

For Each rngcell In Range("A3:G3" & Range("A" & Rows.Count).End(xlUp).Row)

Ch1 = DateDiff("d", Range("A" & rngcell.Row).Value, LValue)
Ch2 = DateDiff("d", LValue, Range("B" & rngcell.Row).Value)

If Ch1 >= 0 And Ch2 >= 0 Then
Worksheet(""cal").Range("R1") = lr_Total
End If

Next

My program get error. How to run 2 worksheet at the same time in the loop?
Or got better suggestion?

Kenneth Hobs
11-05-2011, 10:15 PM
Please be more specific on the error. F8 will step through the code. Obviously, unequal quotes cause a syntax error.

e.g.
Worksheet(""cal").Range("R1") = lr_Total
Select and Activate are seldom needed. Simply prefix what you need with the worksheet object name.

e.g.
Dim cal as worksheet, lw as worksheet
set cal = Worksheets("Cal")
Set lw = Worksheets("LW")
cal.Range("Ra").value = lr_Total