0

したがって、基本的には、ワークシートの 1 つにハイパーリンクを作成して、いくつかのセルなしで正確に複製できるようにしたいと考えています。

ワークシートを正確に複製できるようにする Microsoft サポート Web サイトでこれを見つけました。

Sub Copier1()
    ActiveWorkbook.Sheets("Invoice").Copy _
       after:=ActiveWorkbook.Sheets("Invoice")
End Sub

より良い例として、請求書ジェネレーターを作成しています。合計を計算するとともに、価格と製品を入力できます。空の新しいワークシートに新しい請求書を作成する簡単なボタンを作成し、請求書番号を 1 つ上げようとしています。

透明な赤のセルは、コピーしてはならないセルです。ただし、コピーする必要がある式が含まれています。「リセット」して請求書番号を1ずつ追加しながら、ワークシート全体をコピーする方法はありますか? 請求書のレイアウトは常に同じであるため、「リセット」する必要があるすべてのセルをマクロ内にハードコーディングできます。

ここに画像の説明を入力

どうすればこれを達成できますか?

4

2 に答える 2

1

これにより、ワークシートがコピーされ、製品情報が消去されます

Sub createNewInvoice()
'this assumes the top portion of the invoice never changes
Dim startRow As Integer
Dim startCol As Integer
Dim invNumber As Integer
Dim ws As Worksheet
Dim invCol As Integer
Dim invRow As Integer

invRow = 8
invCol = 6 'F column
startRow = 18 '18 is the first line of items
startCol = 2 'B

'get the invoice number
invNumber = CInt(ActiveWorkbook.Sheets("Invoice").Cells(invRow, invCol).Value)
'set the worksheet object
Set ws = ActiveWorkbook.Sheets("Invoice")
'copy after invoice
ws.Copy After:=ws

'update our invoice number
ws.Cells(invRow, invCol).Value = invNumber + 1
'make the worksheet active
ws.Activate
'clear out our cells with the product info
'clear the first line and delete the rest
Do While Trim(ws.Cells(startRow, startCol).Value) <> ""
    If startRow = 18 Then
        ws.Cells(startRow, startCol).EntireRow.ClearContents
    Else
        ws.Cells(startRow, startCol).EntireRow.Delete shift:=Excel.xlShiftUp
        'reset the row
        startRow = startRow - 1
    End If
    'move to the next row
    startRow = startRow + 1
Loop

'release the worksheet object
Set ws = Nothing


End Sub
于 2013-11-19T00:40:08.593 に答える