簡體   English   中英

如何在 With..End With 塊中復制值(而不是格式)?

[英]How do I copy values (and not the formatting) within a With..End With block?

我曾嘗試將 .PasteSpecial xlPasteValues 和 .value 結合到代碼中。 但似乎無法做到正確。

Private Sub CommandButton1_Click()

Dim wsSource, wsTarget As Worksheet
Dim i, iLastSource, iRowTarget, count As Long
Dim cell As Range

Set wsSource = Worksheets("Stig Jan")
iLastSource = wsSource.Cells(Rows.count, 1).End(xlUp).Row

Set wsTarget = Worksheets("Laura Jan")
count = 0
With wsSource
iRowTarget = wsTarget.Cells(Rows.count, 1).End(xlUp).Row + 1
For i = 36 To iLastSource
  Set cell = .Cells(i, 4)
  If cell.Font.Bold = False Then
    If cell.Value = "Fælles" Or cell.Value = "Lagt Ud" Then
      .Rows(i).Columns("A:H").Copy wsTarget.Range("A" & iRowTarget)
      wsTarget.Range("D" & iRowTarget).ClearContents
      iRowTarget = iRowTarget + 1
      count = count + 1
    End If
  End If
If cell.Value = "Fælles" Or cell.Value = "Lagt Ud" Then
 wsSource.Rows(i).Columns("A:H").Font.Bold = True
End If
Next
End With

如果要使用價值轉移,請更改:

.Rows(i).Columns("A:H").Copy wsTarget.Range("A" & iRowTarget)

wsTarget.Range("A" & iRowTarget & ":H" & iRowTarget).Value = .Range("A" & i & ":H" & i).Value

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM