返回列表 上一主題 發帖

請幫忙翻譯一下程式

回復 23# GBKEE


    請問 With Worksheets("customer").Range(Cells(1, 11), Cells(12, e))這句是否有問題?我想將range設定不固定由A11開始到L欄最後一列畫框線
e = Worksheets("customer").Range("A" & Worksheets("customer").Rows.Count).End(xlUp).Row
With Worksheets("customer").Range(Cells(1, 11), Cells(12, e))
.Borders.LineStyle = 1

.Borders.LineStyle = 1

.Borders.ColorIndex = 0

.BorderAround , 2, 0
End With

TOP

回復 31# 198188
Cells(列數, 欄數)
   
With Worksheets("customer").Range(Cells(1, 11), Cells( e,12))
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 32# GBKEE


    出現run-time error'9' subscript out of range

TOP

回復 33# 198188
你須學會程式碼的偵錯.
VBA視窗中,滑鼠移到有錯誤的程序,按F8逐行執行來看將,是那一行程式碼的發生錯誤.

感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 34# GBKEE


     e = Worksheets("customer").Range("A" & Worksheets("customer").Rows.Count).End(xlUp).Row

TOP

回復 35# 198188
Worksheets("customer") 這工作表找不到???
你程式碼所在的的專案(活頁簿)是與 Worksheets("customer")同一個活頁簿嗎???
如不是須指明(活頁簿)->   Workbooks ("???.XLS").Worksheets("customer").............
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 36# GBKEE

With Worksheets(customer).Range(Cells(11, 1), Cells(e, 12))
    現在這句出現RUN-TIME ERROR '1004' APPLICATION-DEFINED OR OBJECT-DEFINED ERROR

TOP

本帖最後由 GBKEE 於 2013-4-17 17:42 編輯

回復 37# 198188

參考這裡
可能發生這個問題,如果有一個或多個儲存格 (儲存格範圍) 的陣列中包含設定為包含超過 911 個字元的字元字串。
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 38# GBKEE


    我是用excel2010版,在同一個excel內create 一個新的sheets 然後在這個sheets畫框線
excel2010版是否也一樣?

TOP

  1. Sub Schedule()
  2.   Dim I As Double
  3.   Dim cnt As Double
  4.   Dim customer As String
  5.   Dim z As String
  6.   Dim a As Integer
  7.   Dim b As Integer
  8.   Dim c As Integer
  9.   Dim d As Integer
  10.   Dim e As Integer
  11.   Dim f As Integer
  12.   Dim m As Double
  13.   Dim FRng As Range
  14.   Dim Rng As Range
  15.   a = Worksheets("Oracle").Range("A" & Worksheets("Oracle").Rows.Count).End(xlUp).Row
  16.   b = Worksheets("Client Detial").Range("A" & Worksheets("Client Detial").Rows.Count).End(xlUp).Row
  17.   c = Worksheets("Rule").Range("A" & Worksheets("Rule").Rows.Count).End(xlUp).Row
  18. d = 1
  19. Do
  20.   cnt = 11
  21.    
  22.   z = Worksheets("Rule").Cells(d, 1).Value
  23.   customer = z
  24.   Worksheets("Form").Copy After:=Worksheets(Worksheets.Count)
  25.   
  26.   Worksheets(Worksheets.Count).Name = customer
  27.   Worksheets(customer).Range("J4").Value = Date

  28. For I = 2 To a
  29.   If Worksheets("Oracle").Cells(I, 5).Value = customer And Worksheets("Oracle").Cells(I, 20).Value <> 0 Then
  30.   Set FRng = Worksheets(customer).Range("B:B").Find(Worksheets("Oracle").Cells(I, 1).Value, lookat:=xlWhole, SearchDirection:=xlPrevious)
  31.   If FRng Is Nothing Then
  32.   Set Rng = Worksheets("Filter").Range("A:A").Find(Worksheets("Oracle").Cells(I, 1), lookat:=xlWhole)
  33.   If Rng Is Nothing Then
  34.   Worksheets(customer).Cells(cnt, 1).Value = Worksheets("Oracle").Cells(I, 7).Value
  35.   Worksheets(customer).Cells(cnt, 2).Value = Worksheets("Oracle").Cells(I, 1).Value
  36.   Worksheets(customer).Cells(cnt, 4).Value = Worksheets("Oracle").Cells(I, 24).Value
  37.   Worksheets(customer).Cells(cnt, 5).Value = Worksheets("Oracle").Cells(I, 14).Value
  38.   Worksheets(customer).Cells(cnt, 6).Value = Worksheets("Oracle").Cells(I, 12).Value
  39.   Worksheets(customer).Cells(cnt, 7).Value = Worksheets("Oracle").Cells(I, 26).Value
  40.   Worksheets(customer).Cells(cnt, 8).Value = Worksheets("Oracle").Cells(I, 41).Value
  41.   Worksheets(customer).Cells(cnt, 9).Value = Split(Worksheets("Oracle").Cells(I, 42).Value, "/")(0)
  42.   Worksheets(customer).Cells(cnt, 10).Value = Worksheets("Oracle").Cells(I, 27).Value
  43.   Worksheets(customer).Cells(cnt, 11).Value = Worksheets("Oracle").Cells(I, 28).Value
  44.   Worksheets(customer).Cells(cnt, 13).Value = Worksheets("Oracle").Cells(I, 20).Value
  45.   Worksheets(customer).Cells(cnt, 14).Value = Worksheets("Oracle").Cells(I, 18).Value
  46.   Worksheets(customer).Cells(cnt, 15).Value = Worksheets("Oracle").Cells(I, 2).Value
  47.   Worksheets(customer).Cells(cnt, 16).Value = Worksheets("Oracle").Cells(I, 60).Value
  48.   If Trim(Worksheets("Oracle").Cells(I, 8).Value) = "" Then
  49.   Worksheets(customer).Cells(cnt, 3).Value = "NO"
  50.   Else
  51.   Worksheets(customer).Cells(cnt, 3).Value ="YES"
  52.   End If
  53.   cnt = cnt + 1
  54.    End If
  55.    End If
  56.   End If
  57.   
  58.   If Worksheets("Oracle").Cells(I, 5).Value = customer And Trim(Worksheets("Oracle").Cells(I, 20).Value) = "" Then
  59.   Set FRng = Worksheets(customer).Range("B:B").Find(Worksheets("Oracle").Cells(I, 1).Value, lookat:=xlWhole, SearchDirection:=xlPrevious)
  60.   If FRng Is Nothing Then
  61.   Set Rng = Worksheets("Filter").Range("A:A").Find(Worksheets("Oracle").Cells(I, 1), lookat:=xlWhole)
  62.   If Rng Is Nothing Then
  63.   Worksheets(customer).Cells(cnt, 1).Value = Worksheets("Oracle").Cells(I, 7).Value
  64.   Worksheets(customer).Cells(cnt, 2).Value = Worksheets("Oracle").Cells(I, 1).Value
  65.   Worksheets(customer).Cells(cnt, 4).Value = Worksheets("Oracle").Cells(I, 24).Value
  66.   Worksheets(customer).Cells(cnt, 5).Value = Worksheets("Oracle").Cells(I, 14).Value
  67.   Worksheets(customer).Cells(cnt, 6).Value = Worksheets("Oracle").Cells(I, 12).Value
  68.   Worksheets(customer).Cells(cnt, 7).Value = Worksheets("Oracle").Cells(I, 26).Value
  69.   Worksheets(customer).Cells(cnt, 8).Value = Worksheets("Oracle").Cells(I, 41).Value
  70.   Worksheets(customer).Cells(cnt, 10).Value = Worksheets("Oracle").Cells(I, 27).Value
  71.   Worksheets(customer).Cells(cnt, 11).Value = Worksheets("Oracle").Cells(I, 28).Value
  72.   Worksheets(customer).Cells(cnt, 13).Value = Worksheets("Oracle").Cells(I, 20).Value
  73.   Worksheets(customer).Cells(cnt, 14).Value = Worksheets("Oracle").Cells(I, 18).Value
  74.   Worksheets(customer).Cells(cnt, 15).Value = Worksheets("Oracle").Cells(I, 2).Value
  75.   Worksheets(customer).Cells(cnt, 16).Value = Worksheets("Oracle").Cells(I, 60).Value
  76.   If Trim(Worksheets("Oracle").Cells(I, 8).Value) = "" Then
  77.   Worksheets(customer).Cells(cnt, 3).Value = "NO"
  78.   Else
  79.   Worksheets(customer).Cells(cnt, 3).Value = "YES"
  80.   End If
  81.   If Trim(Worksheets("Oracle").Cells(I, 42).Value) = "" Then
  82.   Worksheets(customer).Cells(cnt, 9).Value = ""
  83.   Else
  84.   Worksheets(customer).Cells(cnt, 9).Value = Split(Worksheets("Oracle").Cells(I, 42).Value, "/")(0)
  85.   End If
  86.   cnt = cnt + 1
  87.    End If
  88.    End If
  89.    End If
  90.    
  91.   If Worksheets("Oracle").Cells(I, 5).Value = customer And Worksheets("Oracle").Cells(I, 20).Value = 0 And Worksheets("Oracle").Cells(I, 28).Value >= Date Then
  92.   Set FRng = Worksheets(customer).Range("B:B").Find(Worksheets("Oracle").Cells(I, 1).Value, lookat:=xlWhole, SearchDirection:=xlPrevious)
  93.   If FRng Is Nothing Then
  94.   Set Rng = Worksheets("Filter").Range("A:A").Find(Worksheets("Oracle").Cells(I, 1), lookat:=xlWhole)
  95.   If Rng Is Nothing Then
  96.   Worksheets(customer).Cells(cnt, 1).Value = Worksheets("Oracle").Cells(I, 7).Value
  97.   Worksheets(customer).Cells(cnt, 2).Value = Worksheets("Oracle").Cells(I, 1).Value
  98.   Worksheets(customer).Cells(cnt, 4).Value = Worksheets("Oracle").Cells(I, 24).Value
  99.   Worksheets(customer).Cells(cnt, 5).Value = Worksheets("Oracle").Cells(I, 14).Value
  100.   Worksheets(customer).Cells(cnt, 6).Value = Worksheets("Oracle").Cells(I, 12).Value
  101.   Worksheets(customer).Cells(cnt, 7).Value = Worksheets("Oracle").Cells(I, 26).Value
  102.   Worksheets(customer).Cells(cnt, 8).Value = Worksheets("Oracle").Cells(I, 41).Value
  103.   Worksheets(customer).Cells(cnt, 9).Value = Split(Worksheets("Oracle").Cells(I, 42).Value, "/")(0)
  104.   Worksheets(customer).Cells(cnt, 10).Value = Worksheets("Oracle").Cells(I, 27).Value
  105.   Worksheets(customer).Cells(cnt, 11).Value = Worksheets("Oracle").Cells(I, 28).Value
  106.   Worksheets(customer).Cells(cnt, 13).Value = Worksheets("Oracle").Cells(I, 20).Value
  107.   Worksheets(customer).Cells(cnt, 14).Value = Worksheets("Oracle").Cells(I, 18).Value
  108.   Worksheets(customer).Cells(cnt, 15).Value = Worksheets("Oracle").Cells(I, 2).Value
  109.   Worksheets(customer).Cells(cnt, 16).Value = Worksheets("Oracle").Cells(I, 60).Value
  110.   If Trim(Worksheets("Oracle").Cells(I, 18).Value) <> "" Then Worksheets(customer).Cells(cnt, 12).Value = "眒葆遴"
  111.   If Trim(Worksheets("Oracle").Cells(I, 8).Value) = "" Then
  112.   Worksheets(customer).Cells(cnt, 3).Value = "NO"
  113.   Else
  114.   Worksheets(customer).Cells(cnt, 3).Value = "YES"
  115.   End If
  116.   cnt = cnt + 1
  117.    End If
  118.    End If
  119.    End If
  120.   Next I

  121. For I = 2 To b
  122. If Worksheets("Client Detial").Cells(I, 1).Value = customer Then
  123. Worksheets(customer).Cells(5, 3).Value = Worksheets("Client Detial").Cells(I, 4).Value & " - " & Worksheets("Client Detial").Cells(I, 5).Value
  124. Worksheets(customer).Cells(6, 3).Value = Worksheets("Client Detial").Cells(I, 8).Value
  125. End If
  126. Next I

  127. e = Worksheets(customer).Range("A" & Worksheets(customer).Rows.Count).End(xlUp).Row

  128. With Worksheets(customer).Range(Cells(11, 1), Cells(e, 12))

  129. .Borders.LineStyle = 1

  130. .Borders.LineStyle = 1

  131. .Borders.ColorIndex = 0

  132. .BorderAround , 2, 0
  133. End With

  134. d = d + 1
  135. Loop Until d > c
  136. End Sub
複製代碼
回復 38# GBKEE

如果我合在一起運行就會出現那問題,但是如果我將下面這段分開另外一個獨立的程式,就沒有問題
e = Worksheets(customer).Range("A" & Worksheets(customer).Rows.Count).End(xlUp).Row

With Worksheets(customer).Range(Cells(11, 1), Cells(e, 12))

.Borders.LineStyle = 1

.Borders.LineStyle = 1

.Borders.ColorIndex = 0

.BorderAround , 2, 0
End With

TOP

        靜思自在 : 稻穗結得越飽滿,越會往下垂,一個人越有成就,就要越有謙沖的胸襟。
返回列表 上一主題