2016-03-21 44 views
-2
細胞

它是一種非常基本的問題,我是很新的this.Please幫助 我需要創建SKU數量的拉布勒格式和數量,然後打印出來 EG: 表1(採購訂單)有兩個圖層宏引用Excel的

Sku   Qty 

Bracelets-BB003 6 

Bracelets-BB004 8 

Bracelets-BB029 5 

我有大約500多行。

我需要的數據在下面的格式

Bracelets-BB003     
     6         




Bracelets-BB004  
     8 

Bracelets-BB004 

,這樣我可以打印並切斷他們的個人標籤

詳細說明:表1名:採購訂單

輸出格式:

sku name 

quantity 

請幫忙!

回答

0

如果我正確理解你的問題,這應該這樣做:

Sub LabelPrint() 

    Dim exWSInput as Excel.Worksheet, exWSOutput as Excel.Worksheet 
    Dim i as Long 
    Dim vItem as Variant 

    Application.ScreenUpdating = False 

    Set exWSInput = ThisWorkbook.Sheets("Input values sheetname") ' Change sheetname 
    Set exWSOutput = ThisWorkbook.Sheets("Output values sheetname") ' Change sheetname 

    With exWSInput 

     ' Loop through rows 
     For i = 1 to 500 ' change numbers accordingly 
      vItem = Split(.Cells(i,2), Chr(32)) ' Change "2" to appropriate column 

      ' insert split values into output (destination) sheet 
      exWSOutput.Cells(i, 2) = vItem(0) ' Change "2" to appropriate column 
      exWSOutput.Cells(i, 3) = CLng(vItem(1)) ' Change "3" to appropriate column 
     Next i 
    End With 

    Application.ScreenUpdating = True 

End Sub 

請注意,您必須調整在循環中的引用和行號,使其工作,所以請閱讀註釋。

0

試試這個

Option Explicit 

Sub LabelPrint() 

Dim skuNumberSht As Worksheet, labelsSht As Worksheet 
Dim iniRow As Long, lastRow As Long 

Set skuNumberSht = ThisWorkbook.Sheets("SkuNumber") ' <== change "input" sheet name as per your needs 
Set labelsSht = ThisWorkbook.Sheets("Labels") ' <== change "output" sheet name as per your needs 

With skuNumberSht.Columns("B").SpecialCells(xlCellTypeConstants, xlNumbers) '<== change "Qty" column index as per your needs 
    iniRow = .Rows(1).Row 
    lastRow = .Areas(.Cells.Count).Row 
End With 

With labelsSht.Cells(iniRow, 1).Resize(2) 
    .Formula = Application.WorksheetFunction.Transpose(Array("=" & skuNumberSht.Name & "!RC", "=" & skuNumberSht.Name & "!R[-1]C[+1]")) 
    .Copy .Resize(lastRow - iniRow + 2) 
End With 

End Sub 

你的作品有「輸入」張只要任何行,因爲他們是「配對」(行與兩列數據和一個空白行)

您只需根據需要更改工作表名稱和列索引中的「數量」即可。