如何設定複製迴圈sheet1複製儲存格至sheet2固定位置????
- 帖子
- 2848
- 主題
- 10
- 精華
- 0
- 積分
- 2903
- 點名
- 0
- 作業系統
- 〔略〕
- 軟體版本
- 〔略〕
- 閱讀權限
- 100
- 性別
- 男
- 來自
- 〔略〕
- 註冊時間
- 2013-5-13
- 最後登錄
- 2026-7-25
|
程式構想:
1.〔標籤清單〕工作表前3列,事先設定好表格樣式(只有標題文字,未填內容),
一排要幾欄(視列印大小),可由此決定,貼入資料時,即以此為樣本往右往下轉貼。
2.貼入資料時,從第4列開始,樣式就用前3列為來源,再逐一填入資料,
處理完成後,再刪去前3列。
3.執行〔清除〕,即可恢復原狀(爾後仍可重新更改樣式,程式只依樣複製)- Sub 轉出()
- Dim R&, xR As Range, xH As Range, xE As Range
- Call 清除
- R = [標籤清單!A65536].End(xlUp).Row
- If R < 2 Then Exit Sub
- Set xH = [標籤樣式!A4]: Set xE = xH
-
- For Each xR In [標籤清單!A2].Resize(R - 1)
- If xH = "" Then [標籤樣式!1:3].Copy xE
- xE(2, 2) = xR
- xE(3, 2) = xR(1, 2)
- Set xE = xE(1, 3)
- If xE = "" Then Set xH = xH(4): Set xE = xH
- Next
- [標籤樣式!1:3].EntireRow.Delete
- Application.Goto [標籤樣式!A1]
- End Sub
複製代碼
附件下載:
財產標籤製作v01.rar (16.22 KB)
|
|
|
|
|
|
|
|
- 帖子
- 552
- 主題
- 6
- 精華
- 0
- 積分
- 576
- 點名
- 0
- 作業系統
- win7
- 軟體版本
- office 2010
- 閱讀權限
- 50
- 性別
- 男
- 註冊時間
- 2015-2-8
- 最後登錄
- 2026-9-10
  
|
2#
發表於 2015-9-13 22:36
| 只看該作者
回復 1# poke0817
是這樣嗎?
我把標籤樣式改到Sheet3以應第2個問題- Public Sub ex()
- Dim rng As Range, r%, c%
- Sheet3.Range("a1:h" & Sheet3.Cells(Rows.Count, 1).End(xlUp).Row).Delete
- r = 1
- c = 1
- For i = 1 To 8 Step 2
- Sheet3.Columns(i).ColumnWidth = 9.65
- Sheet3.Columns(i + 1).ColumnWidth = 18.13
- Next
- For Each rng In Sheet1.Range("a2:a" & Sheet1.Cells(Rows.Count, 1).End(xlUp).Row)
- With Sheet3
- If c < 8 Then
- With .Range(.Cells(r, c), .Cells(r + 2, c + 1))
- .HorizontalAlignment = xlCenter
- .VerticalAlignment = xlCenter
- .WrapText = False
- .Orientation = 0
- .AddIndent = False
- .IndentLevel = 0
- .ShrinkToFit = True
- .ReadingOrder = xlContext
- .Borders(xlDiagonalDown).LineStyle = xlNone
- .Borders(xlDiagonalUp).LineStyle = xlNone
- With .Borders(xlEdgeLeft)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With .Borders(xlEdgeTop)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With .Borders(xlEdgeBottom)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With .Borders(xlEdgeRight)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlMedium
- End With
- With .Borders(xlInsideVertical)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With .Borders(xlInsideHorizontal)
- .LineStyle = xlContinuous
- .ColorIndex = xlAutomatic
- .TintAndShade = 0
- .Weight = xlThin
- End With
- With .Font
- .Name = "標楷體"
- End With
- End With
- With .Range(.Cells(r, c), .Cells(r, c + 1))
- .MergeCells = True
- .Value = "XX企業股份有限公司"
- With .Font
- .Size = 14
- End With
- End With
- .Cells(r + 1, c) = "財產編碼"
- .Cells(r + 1, c + 1) = rng
- .Cells(r + 2, c) = "品名"
- .Cells(r + 2, c + 1) = rng.Offset(, 1)
- c = c + 2
- End If
- If c > 8 Then
- c = 1
- r = r + 3
- End If
- End With
- Next
- End Sub
複製代碼 |
|
|
|
|
|
|
|