我有一张工作表,当工作表打开时,它当前会生成一组数据,但我想在生成时为这些行添加顶部和底部边框。我很遗憾不知道如何添加,我认为它是下面的,但这只是错误,建议它不是一个有效的参数。
我认为可能就是这样:
With InputWorksheet ' Set the worksheet
.Hyperlinks.Add Anchor:=.Range("A" & row_ptr), Address:="", SubAddress:=AddStr, TextToDisplay:=DataSourceWorksheet.Range("O" & i).Value
.Borders (xlEdgeTop), LineStyle = xlContinuous, ColorIndex = 0, TintAndShade = 0, Weight = xlThin
End With
完整代码:
rownbrMA_Inflight = DataSourceWorksheet.Range("C" & Rows.Count).End(xlUp).Row 'Set the Management Action row count
row_ptr = 31 'Set starting row on home page for new table values
For i = 8 To rownbrMA_Inflight 'Not sure of the reason for this
If DataSourceWorksheet.Range("C" & i).Value = "Open" Then 'Only copy items with status as "Open"
InputWorksheet.Rows(row_ptr).Insert Shift:=xlDown 'Select the row_ptr and insert a new row with formating from above
AddStr = "MA_Inflight!" & "$F$" & CStr(i) ' String to be added is the Cell value for the hyperlink
With InputWorksheet ' Set the worksheet
.Hyperlinks.Add Anchor:=.Range("A" & row_ptr), Address:="", SubAddress:=AddStr, TextToDisplay:=DataSourceWorksheet.Range("O" & i).Value
End With ' End Hyperlink function
'------------------------------------ '
InputWorksheet.Range("B" & row_ptr).Value = DataSourceWorksheet.Range("H" & i).Value ' Set the 6 week due date
InputWorksheet.Range("C" & row_ptr).Value = DataSourceWorksheet.Range("I" & i).Value ' Set the MA Close date
InputWorksheet.Range("D" & row_ptr).Value = DataSourceWorksheet.Range("K" & i).Value ' Set the Service Assurance Owner
row_ptr = row_ptr + 1 ' Last row is row_ptr +1
End If ' End the set loop
Next i ' Move to next row
非常感谢任何帮助。
答案 0 :(得分:2)
尝试
.Range("A" & row_ptr).Borders (xlEdgeTop), LineStyle = xlContinuous, ColorIndex = 0, TintAndShade = 0, Weight = xlThin
或
.Rows(row_ptr).Borders (xlEdgeTop), LineStyle = xlContinuous, ColorIndex = 0, TintAndShade = 0, Weight = xlThin
答案 1 :(得分:0)
那怎么样?
With InputSheet.Range("A" & row_ptr).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
或
With InputSheet.Rows(row_ptr).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
答案 2 :(得分:0)
根据需要更改工作表名称。目前尚不清楚要应用边框的范围。
Sub x()
Dim row_ptr As Long
row_ptr = 5
With ActiveSheet
With .Rows(row_ptr).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End With
End Sub