[英]Pass VBA Sub a Range
我保持這個錯誤“類型不匹配”
我希望能夠通過傳遞我想要顯示的范圍和值來格式化我的表中的單元格。
誰能指出我要去哪里了?
Sub Layout()
Call Create_Box("A1:A2", 10)
End Sub
Sub Create_Box(R As Range, V As String)
Dim box As Object
Set box = Range(R)
With box
.Merge
.Value = Box_value
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Border.Style = continous
.Border.Color = black
.Border.Weight = xlThick
End With
End Sub`
您傳入的參數不是Range對象 ; 只是表示區域對象的本地Address屬性的字符串。
Sub Layout()
with activesheet '<-set this explicitly to something like With Sheets("Sheet1")
Call Create_Box(.range("A1:A2"), 10)
end with
End Sub
Sub Create_Box(R As Range, V As String)
With R
.Merge
.Value = Box_value
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Border.Style = xlContinuous
.Border.Color = 0
.Border.Weight = xlThick
End With
End Sub
將其作為范圍對象傳遞。
Sub Layout()
Dim r1 As Range
Dim ws As Excel.Worksheet
Set ws = Application.ActiveSheet
Set r1 = ws.Range("A1:A2")
Call Create_Box(r1, "10")
End Sub
Sub Create_Box(R As Range, V As String)
Dim box As Object
Set box = Range(R.Address)
With box
.Merge
.Value = Box_value
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
.Border.Style = continous
.Border.Color = black
.Border.Weight = xlThick
End With
結束子
應該這樣做:
Sub Create_Box(R As String, V As String)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.