返回列表 上一主題 發帖

匯入總表數據bug

匯入總表數據bug

各位大大好,初來乍到想詢問一個程式語言
小弟遇到狀況如下
1.將5個專案分別以複製方式貼上"經管表格" (OK)
2.貼上後再將C欄選取範圍匯入"總表" (不OK)
不OK的原因是...
當匯入過去後,全部數值會變成一樣的(求解)
因為寫的這個程式碼感覺很暴力,是否有比較簡單的寫法?(求解)

以下是程式碼,再麻煩各位協助除錯!!! 感恩感恩
Sub summary2()

    工作表1.Activate
   
    'If Sheet <> 專案 Then Exit Sub '非有專案的標題 不動作
    For j = 3 To 7
        For i = 2 To 6
        
           Range("B3:D58").ClearContents
           Sheets(j).Range("B3:D58").Copy Destination:=[b3]
   
               
            工作表7.Cells(4, i) = [c3]
            工作表7.Cells(5, i) = [c5]
            工作表7.Cells(6, i) = [c6]
            工作表7.Cells(7, i) = [c7]
            工作表7.Cells(8, i) = [c8]
            工作表7.Cells(9, i) = [c9]
            工作表7.Cells(10, i) = [c10]
            工作表7.Cells(11, i) = [c11]
            工作表7.Cells(12, i) = [c12]
            工作表7.Cells(13, i) = [c13]
            工作表7.Cells(14, i) = [c14]
            工作表7.Cells(15, i) = [c15]
            工作表7.Cells(16, i) = [c16]
            工作表7.Cells(17, i) = [c17]
            工作表7.Cells(18, i) = [c18]
            工作表7.Cells(19, i) = [c19]
            工作表7.Cells(20, i) = [c20]
            工作表7.Cells(21, i) = [c21]
            工作表7.Cells(22, i) = [c22]
            工作表7.Cells(23, i) = [c23]
            工作表7.Cells(24, i) = [c24]
            工作表7.Cells(25, i) = [c25]
            工作表7.Cells(26, i) = [c26]
            工作表7.Cells(27, i) = [c27]
            工作表7.Cells(28, i) = [c28]
            工作表7.Cells(29, i) = [c29]
            工作表7.Cells(30, i) = [c30]
            工作表7.Cells(31, i) = [c31]
            工作表7.Cells(32, i) = [c32]
            工作表7.Cells(33, i) = [c33]
            工作表7.Cells(34, i) = [c34]
            工作表7.Cells(35, i) = [c35]
            工作表7.Cells(36, i) = [c36]
            工作表7.Cells(37, i) = [c37]
            工作表7.Cells(38, i) = [c38]
            工作表7.Cells(39, i) = [c39]
            工作表7.Cells(40, i) = [c40]
            工作表7.Cells(41, i) = [c41]
            工作表7.Cells(42, i) = [c42]
            工作表7.Cells(43, i) = [c43]
            工作表7.Cells(44, i) = [c44]
            工作表7.Cells(45, i) = [c45]
            工作表7.Cells(46, i) = [c46]
            工作表7.Cells(47, i) = [c47]
            工作表7.Cells(48, i) = [c48]
            工作表7.Cells(49, i) = [c49]
            工作表7.Cells(50, i) = [c50]
            工作表7.Cells(51, i) = [c51]
            工作表7.Cells(52, i) = [c52]
            工作表7.Cells(53, i) = [c53]
            工作表7.Cells(54, i) = [c54]
            工作表7.Cells(55, i) = [c55]
            工作表7.Cells(56, i) = [c56]
            工作表7.Cells(57, i) = [c57]
            工作表7.Cells(58, i) = [c58]
            
           
         Next
    Next
   
    工作表7.Activate
   
   

End Sub

圖片.png (276.44 KB)

匯入順序

圖片.png

圖片2.jpeg (184.5 KB)

數值都是一樣的

圖片2.jpeg

圖片3.PNG (9.85 KB)

工作表數量

圖片3.PNG

回復 2# samwang


    請參考!!  謝謝!!
    模組主要放在modul1

經管會表格報告.zip (250.54 KB)

附件

TOP

寫出了另一個可以導入的
結果變成了B欄被跳過了...悲劇...

Sub test()

    工作表1.Activate
    Set i = 工作表1.Range("C5:C58")
        For j = 2 To 7
        
           Range("B358").ClearContents
           Sheets(j).Range("B358").Copy Destination:=[b3]
        
               
            工作表7.Cells(4, j) = [c3]
            工作表7.Cells(5, j) = [c5]
            工作表7.Cells(6, j) = [c6]
            工作表7.Cells(7, j) = [c7]
            工作表7.Cells(8, j) = [c8]
            工作表7.Cells(9, j) = [c9]
            工作表7.Cells(10, j) = [c10]
            工作表7.Cells(11, j) = [c11]
            工作表7.Cells(12, j) = [c12]
            工作表7.Cells(13, j) = [c13]
            工作表7.Cells(14, j) = [c14]
            工作表7.Cells(15, j) = [c15]
            工作表7.Cells(16, j) = [c16]
            工作表7.Cells(17, j) = [c17]
            工作表7.Cells(18, j) = [c18]
            工作表7.Cells(19, j) = [c19]
            工作表7.Cells(20, j) = [c20]
            工作表7.Cells(21, j) = [c21]
            工作表7.Cells(22, j) = [c22]
            工作表7.Cells(23, j) = [c23]
            工作表7.Cells(24, j) = [c24]
            工作表7.Cells(25, j) = [c25]
            工作表7.Cells(26, j) = [c26]
            工作表7.Cells(27, j) = [c27]
            工作表7.Cells(28, j) = [c28]
            工作表7.Cells(29, j) = [c29]
            工作表7.Cells(30, j) = [c30]
            工作表7.Cells(31, j) = [c31]
            工作表7.Cells(32, j) = [c32]
            工作表7.Cells(33, j) = [c33]
            工作表7.Cells(34, j) = [c34]
            工作表7.Cells(35, j) = [c35]
            工作表7.Cells(36, j) = [c36]
            工作表7.Cells(37, j) = [c37]
            工作表7.Cells(38, j) = [c38]
            工作表7.Cells(39, j) = [c39]
            工作表7.Cells(40, j) = [c40]
            工作表7.Cells(41, j) = [c41]
            工作表7.Cells(42, j) = [c42]
            工作表7.Cells(43, j) = [c43]
            工作表7.Cells(44, j) = [c44]
            工作表7.Cells(45, j) = [c45]
            工作表7.Cells(46, j) = [c46]
            工作表7.Cells(47, j) = [c47]
            工作表7.Cells(48, j) = [c48]
            工作表7.Cells(49, j) = [c49]
            工作表7.Cells(50, j) = [c50]
            工作表7.Cells(51, j) = [c51]
            工作表7.Cells(52, j) = [c52]
            工作表7.Cells(53, j) = [c53]
            工作表7.Cells(54, j) = [c54]
            工作表7.Cells(55, j) = [c55]
            工作表7.Cells(56, j) = [c56]
            工作表7.Cells(57, j) = [c57]
            工作表7.Cells(58, j) = [c58]
        
    Next
   
    工作表7.Activate
   
    'Columns("B:B").Delete
   
   

End Sub

TOP

回復 5# samwang


   
這個沒辦法作業...
沒有bug 但是總表沒有生成

TOP

回復 7# samwang


    感謝你不厭其煩的測試!!
但沒辦法成功引入...反而原有的"經管表格"內容也被清空了!!
有定義作用頁面是在哪個嗎?

擷取1.PNG (78.86 KB)

擷取1.PNG

TOP

回復 9# samwang


  有點想哭!
是因為版本不同的關係所以有所差別??
因為真的帶不出來...

TOP

反而原有的"經管表格"內容也被清空了
>> 對不起,清除總表資料 = "",前面少了. 請自行加入,我也把程 ...
samwang 發表於 2022-5-29 10:58



    大師,想問個!!
如果以我原本的一長串的方式是可以帶的過去的
但現在卡住的有兩點
1.如同您寫的→ If InStr(sh.Name, "專案") Then '工作名稱有專案
   我也想僅sheet Name 有"專案" 才能作業!!
2.B的欄位都會被跳過

這兩個以原本寫的方式是需要再加什麼迴圈嗎?
有嘗試把你的語法帶入我的語法內,但是沒辦法順利成功

藥再麻煩大大了!

TOP

With sheets(1) 先設停止點,然後按F5執行,再確認字典有無資料,正確應該要有資料,請確認,謝謝
samwang 發表於 2022-5-29 11:30



   這個步驟經過確認,有東西可以帶出來唷!

2.PNG (168.61 KB)

2.PNG

TOP

With sheets(1) 先設停止點,然後按F5執行,再確認字典有無資料,正確應該要有資料,請確認,謝謝
samwang 發表於 2022-5-29 11:30


剛剛又重複嘗試了一次,沒成功帶出...


2.B的欄位都會被跳過
>> 看你的程式,個分頁資料-->"經營表格"-->C欄資料--> 總表
看不懂你實際需求是 ...
samwang 發表於 2022-5-29 11:41



  設定是
"經管表格" C欄的資料可以帶入 "總表"依名稱填入對應的數據
但小弟剛接觸VBA不久,不知道為什麼,數據帶入了,但是B欄位沒有被引動的感覺,反而是從總表的C欄開始動作

不好意思,礙於權限關係!! 每小時只能回復三帖... 很緊張這種回復方式

TOP

依據你的測試#14 有成功,#15又失敗,你又說字典有資料
所以有可能你的總表第4列(如附圖)被清除然後執 ...
samwang 發表於 2022-5-29 19:30



所以有可能你的總表第4列(如附圖)被清除然後執行結果就會失敗
第4列的各分頁的工作名稱不能清除
因為那是字典匯出時比對的條件之一


大大 沒錯喔!!是有數據生成的!!
但有一件事情是,若這個編碼再下次會更新是不一樣的(非作業,實戰使用)
是不是變成要先將專案代碼先匯入總表內,再將後續的數值呼叫出來呢?

TOP

        靜思自在 : 【停滯不前,終無所得】人都迷於尋找奇蹟,因而停滯不前;縱使時間再多、路再長,也了無用處,終無所得。
返回列表 上一主題