2014-01-15 67 views
0

爲了從存在於單個Excel工作簿到目的地232個的Excel工作表複製數據的Excel工作表存在於與目標工作表中的行名稱的標準相同的工作簿應該與工作表名稱相同。因爲在Excel文件中命名工作表時,我們對其大小有限制,因此對於某些工作表而言,名稱被寫入較短,但在destiantion工作表中名稱的名稱都寫在fullform.So一些工作表中的數據不accumulated.How來解決這個問題?請help.I是新來的VBA要從232個Excel工作表存在於單個Excel工作簿數據複製到目的地worksheet.The行名和工作表的名稱應該是相同

Private Sub CommandButton1_Click() 
Dim sheetName As String 
Dim i As Integer 
i = 2 
Do While Cells(i, 1).Value <> "" 

     sheetName = Cells(i, 1) 
     Cells(i, 4) = Sheets(sheetName).Cells(190, 7).Value 
     Cells(i, 5) = Sheets(sheetName).Cells(191, 7).Value 
     Cells(i, 6) = Sheets(sheetName).Cells(192, 7).Value 
     Cells(i, 7) = Sheets(sheetName).Cells(193, 7).Value 
     Cells(i, 8) = Sheets(sheetName).Cells(194, 7).Value 
     Cells(i, 9) = Sheets(sheetName).Cells(195, 7).Value 
     Cells(i, 10) = Sheets(sheetName).Cells(196, 7).Value 
     i = i + 1 
Loop 
End Sub 

回答

0

嘗試使用下面的代碼(SI重命名錶時用於表名稱NCE最大長度手動爲31字符可以限制sheetName):

Private Sub CommandButton1_Click() 
Dim sheetName As String 
Dim i As Integer 
i = 2 
Do While Cells(i, 1).Value <> "" 

     sheetName = IIf(Len(Cells(i, 1))>31,Left(Cells(i, 1),31),Cells(i, 1)) 
     Cells(i, 4) = Sheets(sheetName).Cells(190, 7).Value 
     Cells(i, 5) = Sheets(sheetName).Cells(191, 7).Value 
     Cells(i, 6) = Sheets(sheetName).Cells(192, 7).Value 
     Cells(i, 7) = Sheets(sheetName).Cells(193, 7).Value 
     Cells(i, 8) = Sheets(sheetName).Cells(194, 7).Value 
     Cells(i, 9) = Sheets(sheetName).Cells(195, 7).Value 
     Cells(i, 10) = Sheets(sheetName).Cells(196, 7).Value 
     i = i + 1 
Loop 
End Sub 
+0

非常感謝simoco。 – user3045652

+0

我標出來的範圍系的細胞(我,4)=表(SHEETNAME).Cells(190,7).value的 – user3045652

+0

你是如何生成fullnames你的短名字? –

相關問題