我的問題是是否有允許粘貼到特定單元格的 vba excel 命令,如果這些特定單元格已滿,是否找到下一個可用于粘貼資料的特定單元格?
舉個例子
單元格范圍 A1:E5 是我可以粘貼資料的特定單元格范圍。但是 A6:E11 的單元格范圍是我無法粘貼資料并且需要跳轉到下一個可用單元格范圍的單元格欄位
提前感謝有相同問題的主題的答案或方向。
我希望你明白我想說什么。
我沒有代碼。試圖在互聯網上找到鱈魚或類似的東西,但似乎找不到類似的情況。
uj5u.com熱心網友回復:
填空

Sub FillBlanks()
Dim wb As Workbook: Set wb = ThisWorkbook
Dim sws As Worksheet: Set sws = wb.Worksheets("Sheet1")
Dim srg As Range: Set srg = sws.Range("A1").CurrentRegion
Dim dws As Worksheet: Set dws = wb.Worksheets("Sheet2")
Dim drg As Range: Set drg = dws.Columns("A:C")
Dim dcCount As Long: dcCount = drg.Columns.Count
Dim dr As Long: dr = 1
Dim dc As Long: dc = 1
Dim sCell As Range
Dim dCell As Range
For Each sCell In srg.Cells
If Len(CStr(sCell.Value)) > 0 Then ' the source cell is not blank
Do
Set dCell = drg.Cells(dr, dc) ' current destination cell
' Determine the next destination row and column.
If dc < dcCount Then dc = dc 1 Else dc = 1: dr = dr 1
If Len(CStr(dCell.Value)) = 0 Then ' destination cell is blank
sCell.Copy dCell ' copy; more illustrative
'dCell.Value = sCell.Value ' write values; more efficient
Exit Do
'Else ' the destination cell is not blank; do nothing
End If
Loop
'Else ' the source cell is blank; do nothing
End If
Next sCell
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/528569.html
標籤:擅长vba粘贴
上一篇:使用REST-API在Excel中同時編輯或鎖定單元格
下一篇:轉置和重復多列和多行
