n = 14
Do Until n > mm + 14
Range("B" & n).Select
dia = ActiveCell.Offset(0, 0).Value
Select Case dia
Case 1
d = "01"
Case 2
d = "02"
Case 3
d = "03"
Case 4
d = "04"
Case 5
d = "05"
Case 6
d = "06"
Case 7
d = "07"
Case 8
d = "08"
Case 9
d = "09"
Case Else
d = dia
End Select
Workbooks.Open Filename:= _
"E:2008" & ms & "A G0B-" & d & ".xls"
MsgBox "E:2008" & ms & "A G0B-" & d & ".xls"
Sheets("Hoja1").Select
Cells.Find(What:="N2+CO2 (% MOL)", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
inertes = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="CO2", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
co2 = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="Cont H2S mg/m3", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
h2s = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="Cont. O2 % mol", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
o2 = ActiveCell.Offset(0, 2).Value
Cells.Find(What:="Cont. vapor de agua mg/m3", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _
xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
, SearchFormat:=False).Activate
h2o = ActiveCell.Offset(0, 2).Value
inertes1 = Round(inertes, 2)
h2s1 = Round(h2s, 2)
co21 = Round(co2, 2)
o21 = Round(o2, 2)
h2o1 = Round(h2o, 2)
Windows("Setembro 2008.xls").Activate
Range("D" & n) = h2o1
Range("E" & n) = h2s1
Range("F" & n) = o21
Range("G" & n) = inertes1
Range("H" & n) = co21
Windows("A G0B-" & d & ".xls").Activate
ActiveWindow.Close (False)
n = n
n = n + 1
Loop
resp = MsgBox("Relatório finalizado", vbOKOnly)
End Sub
Ela abre uma planilha, copia algumas células e cola em outra já aberta. Mas vai procurando uma a uma, quando chega na 10, por exemplo, e não tem a planilha "E:2008" & ms & "A G0B-" & "10" & ".xls" ele dá erro e pára a execução.
Preciso de uma função que pule esse erro e vá para o próximo(11).
Grato,
Rubens