返回列表 上一主題 發帖

[發問] 將voucher的資料寫入journal出錯

回復 1# Hero2013
  1. my_journal.Cells(i, 7) = my_voucher.Cells(Voucher_First_line, 3) + " " + my_voucher.Cells(Voucher_First_line, 4)
  2. Debug.Print my_voucher.Cells(Voucher_First_line, 3), my_voucher.Cells(Voucher_First_line, 4), my_voucher.Cells(Voucher_First_line, 5)
複製代碼
字串 + 字串 是可以的
字串 &  數字 才正確  
請相看VBA 運算子摘要 的說明




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

TOP

回復 3# Hero2013
試試看
  1. Option Explicit
  2. Sub Ex()
  3.     Dim Ar(), Ay(), Rng As Range, i As Integer, R As Integer
  4.     With Sheets("print")
  5.         For i = .Range("G9").Value To .Range("H9").Value
  6.             With Sheets("Journal")
  7.                 Set Rng = .Range("A5", .Range("A5").End(xlDown)).Find(i, LOOKAT:=xlWhole)
  8.             End With
  9.             If Not Rng Is Nothing Then
  10.                 Do While Rng = i
  11.                     R = R + 1
  12.                     With Rng  
  13.                         ReDim Preserve Ar(1 To R)
  14.                         Ar(R) = Array(.Range("B1").Value, .Range("C1").Value, .Range("G1").Value, .Range("H1").Value, .Range("I1").Value)
  15.                     End With
  16.                     Set Rng = Rng.Offset(1)
  17.                 Loop
  18.                 Ay = Application.Transpose(Ar)
  19.                 R = R + 1
  20.                 ReDim Preserve Ar(1 To R)
  21.                 Ar(R) = Array("", "", "總 數:", Application.Sum(Application.Index(Ay, 4)), Application.Sum(Application.Index(Ay, 5)))
  22.                 'Dr借項 Application.Index(Ay, 4)
  23.                 'Cr貸項 Application.Index(Ay, 5)
  24.                 Ar = Application.Transpose(Application.Transpose(Ar))
  25.                 .[a10:e10].Resize(R).Value = Ar
  26.                 .PageSetup.PrintArea = "A3:" & .[a10:e10].Resize(R).Address  '設定印列範圍
  27.                 .PrintOut           '印列
  28.                 Erase Ar            '重新初始化固定大小陣列的元素,並釋放動態陣列的儲存空間
  29.                 .[a10:e10].Resize(R) = ""
  30.                 R = 0
  31.             End If
  32.         Next
  33.     End With
  34. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 6# Hero2013
修改一下 After(參數):從最後開始搜尋
  1. Set Rng = .Range("A5", .Range("A5").End(xlDown)).Find(i, LOOKAT:=xlWhole, After:=.Range("A5").End(xlDown))
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 知識要用心體會,才能變成自己的智慧。
返回列表 上一主題