我有下面的腳本設置範圍複製到一個電子郵件但是我需要這個範圍從第1列到第13列,同時刪除列7(「1:6」,「8:13」) 我已嘗試各種方法來糾正此錯誤,但每次嘗試都會導致錯誤。發送HTML郵件範圍
這裏是我使用
Set RangeCopy = Sheets("Applications").Range(Cells(1, 1), Cells(R, 13)).SpecialCells(xlCellTypeVisible)
任何幫助表示讚賞代碼。 謝謝。
我有下面的腳本設置範圍複製到一個電子郵件但是我需要這個範圍從第1列到第13列,同時刪除列7(「1:6」,「8:13」) 我已嘗試各種方法來糾正此錯誤,但每次嘗試都會導致錯誤。發送HTML郵件範圍
這裏是我使用
Set RangeCopy = Sheets("Applications").Range(Cells(1, 1), Cells(R, 13)).SpecialCells(xlCellTypeVisible)
任何幫助表示讚賞代碼。 謝謝。
使用Union
是非常乾淨的做法。請參閱下面的代碼給出您的代碼示例。
Dim unionrng As Range
Set unionrng = Application.Union(Sheets("Applications").Range(Cells(1, 1), Cells(r, 6)), _
Sheets("Applications").Range(Cells(1, 8), Cells(r, 13)))
Sheets("Applications").Range(unionrng.Address).SpecialCells (xlCellTypeVisible)
您有幾個選項 - 通過逗號連接範圍地址或構建單獨的範圍並使用Union
方法。請參閱Microsoft幫助中的How to: Refer to Multiple Ranges文章。
你可以嘗試在這樣的循環中使用聯合。
Dim x As Long
Dim y As Long
For y = 1 To 13
For x = 1 To r
If y <> 7 Then
If RangeCopy Is Nothing Then
Set RangeCopy = cells(x, y)
Else
Set RangeCopy = Application.Union(RangeCopy, cells(x, y))
End If
End If
Next x
Next y
謝謝你,我正在尋找幾個小時試圖找到這個。這工作完美。 – Paul