VBA with + if 問題

本帖最後由 travelntravel 於 2017-1-9 17:04 編輯

大家好, VBA超新手一問, 請問以下只能做到第7張的update,  做完唔識去下一張, 咁係打少左D乜野? 謝謝

Sub border()
   
    Dim ws As Worksheet, x As Integer, i As Integer

x = 7

For i = x To Worksheets.Count
Set ws = Worksheets(i)
With ws

If Right(ActiveSheet.Name, 4) = "_PDT" Then

....

ElseIf Right(ActiveSheet.Name, 4) = "_L&D" Then

....

End If

End With
Next i
End Sub

回覆 1# travelntravel

ActiveSheet >>> ws

TOP

本帖最後由 travelntravel 於 2017-1-9 14:57 編輯

唔得,咁佢會將2種結果做晒落第7頁度,其他頁做唔到。

TOP

本帖最後由 狂蜂一號 於 2017-1-9 22:30 編輯
唔得,咁佢會將2種結果做晒落第7頁度,其他頁做唔到。
travelntravel 發表於 2017-1-9 14:24


To add ThisWorkbook. or Workbooks("Book1.xlsx"). before Worksheets may be a good idea.

(Which one is ActiveSheet? Will it be changed? More details?)

TOP

If Right(.Name, 4) = "_PDT" Then
....
ElseIf Right(.Name, 4) = "_L&D" Then
....

TOP

To add ThisWorkbook. or Workbooks("Book1.xlsx"). before Worksheets may be a good idea.

(Which one ...
狂蜂一號 發表於 2017-1-9 22:28


all code are in same excel, 即是由第7張sheet 開始,如pdt 尾的做一樣野,L&D 尾做另一樣野 check 番當時的sheet name 來決定做乜

TOP

If Right(.Name, 4) = "_PDT" Then
....
ElseIf Right(.Name, 4) = "_L&D" Then
....
JL* 發表於 2017-1-10 08:58


runtime error 1004

TOP

runtime error 1004
travelntravel 發表於 2017-1-10 09:26


有冇 debug 過邊句 runtime error?

TOP

有冇 debug 過邊句 runtime error?
JL* 發表於 2017-1-10 10:04


再run過又無問題,但只識做現時個頁, 唔識做之後的頁數

TOP

再run過又無問題,但只識做現時個頁, 唔識做之後的頁數
travelntravel 發表於 2017-1-10 11:12


"但只識做現時個頁" << 咁應該係 if 裡面其他 statements 問題

TOP