试图设置相同的行,但不同的列范围的边界

我基本上有一套汇总表,可以从一百个左右的工作表中获取信息 – 一个摘要是关于当前周期的信息,而我现在正在搞的信息将当前周期信息分解到各个部门的财政年度跟踪表。 我的代码工作得很好,用于移动信息,但是在复制信息之后,我无法获得正确的语法来设置/select正确的范围,以便在新添加的信息周围设置边框。 我移动信息的代码是:

Sub FYFTEE() Dim shtCurrent As Worksheet Dim shtFY As Worksheet Dim LastCol As Long Dim CopyRng As Range With Application .ScreenUpdating = False .EnableEvents = False End With Set shtCurrent = ThisWorkbook.Sheets("Cycle Summary") Set shtFY = ThisWorkbook.Sheets("FY12 D1") Set CopyRng = shtCurrent.Range("$C$12:$C$47") LastCol = shtFY.Cells("5", Columns.Count).End(xlToLeft).Column + 1 With CopyRng shtFY.Cells("5", LastCol).Resize(.Rows.Count, .Columns.Count).Value = .Value End With shtFY.Cells("4", LastCol).Value = shtCurrent.Range("I3").Value With Application .ScreenUpdating = True .EnableEvents = True End With End Sub 

感谢您的build议和指导!

假设你想在每一组复制的数据周围有一组新的边界,声明这个:

 Dim destinationRange As Range 

并将您的With CopyRng语句更改为:

 With CopyRng Set destinationRange = shtFY.Cells("5", LastCol).Resize(.Rows.Count, .Columns.Count) destinationRange.Value = .Value destinationRange.BorderAround Weight:=xlThick End With 

这会给你一个复制过的每一组数据的厚边框。

或者,如果您在目标工作表上的所有内容都需要边框,则可以使用此代替上述代码:

 shtFY.Cells.Borders.LineStyle = xlNone shtFY.UsedRange.BorderAround Weight:=xlThick 

行后:

 shtFY.Cells("4", LastCol).Value = shtCurrent.Range("I3").Value