2012-03-09 48 views
0

我基本上有一組彙總表,從一百個左右的工作表一起提取信息 - 一個摘要是當前週期的信息和我搞亂的信息現在將當前週期信息分解到各個部門會計年度跟蹤表。爲了移動信息,我的代碼工作得很好,但是在複製信息之後,我無法獲得正確的語法來設置/選擇正確的範圍,以便在新添加的信息周圍設置邊框。我移動信息的代碼是:試圖設置相同的行,但不同的列的範圍上的邊界

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 

感謝您的建議和指導!

+0

和問題? – smirkingman 2012-03-09 13:26:32

+0

認真嗎?當信息進入新頁面時,它也沒有邊界...我需要添加邊框,但我無法獲得正確的線條來完成此操作。 – Jon 2012-03-09 13:47:59

回答

2

假設你想要一套新的圍繞每個組拷貝數據的邊界,這樣聲明:

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 
+0

這讓我在需要的地方。感謝您的幫助。 – Jon 2012-03-09 14:13:38

+0

@Jon:沒問題。如果您需要一種方法在目標工作表中的所有數據上添加邊框,而不是一次只有一組數據,請參閱我的更新。 – 2012-03-09 14:17:39

相關問題