我的文件看起来像附件。以下代码段尝试仅在我未指定的工作表上插入行。这将从单元格B3开始,一直向下进行。因此它将在B34处插入一行,因为这是第一行新行,并将删除B3行,因此范围将以指数形式继续。
我相信代码几乎可以做到这一点。我需要完成上述操作,然后再将单元格B4中显示的公式作为公式复制到B5,然后将b4粘贴为值。这样,当运行另一个更新工作簿的宏时,只有带有公式的值会更改,而前几周不会更改。我有图表在这个范围内,因此每次运行不同的宏时,都会显示最新值,并且在该范围和后续图表中将显示一个新值。希望这有道理!
Sub INSERT_NEW_ROWS()
Dim rs As Worksheet
For Each rs In ThisWorkbook.Worksheets
If rs.name <> "3110" And rs.name <> "Data" And rs.name <> "Wholesale" And rs.name <> "Retail" And rs.name <> "Pivot 1" And rs.name <> "Pivot 2" And rs.name <> "Pivot 3" And rs.name <> "Pivot 4" And rs.name <> "Pivot 5" And rs.name <> "Pivot 6" And rs.name <> "Pivot 7" And rs.name <> "Pivot 8" And rs.name <> "Pivot 9" And rs.name <> "Pivot 10" And rs.name <> "Pivot 11" Then
rs.name = rs.Range("B3:B").Value
Next rs
End
' Go to last cell
Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Select
' Copy formula from cell above
Rows(Selection.Row - 1).Copy
Rows(Selection.Row).Insert Shift:=xlDown
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
ws.Range("2:2").Delete
Next ws
End Sub
答案 0 :(得分:1)
我的建议:
array(91) { [0]=> string(6) "537146" [1]=> string(4) "1212" [2]=> string(7) "7902400" [3]=> string(6) "670563" [4]=> string(2) "69" [5]=> string(6) "674789" [6]=> string(6) "576650" [7]=> string(2) "68" [8]=> string(6) "628147" [9]=> string(6) "690316" [10]=> string(2) "71" [11]=> string(6) "831597" [12]=> string(6) "746547" [13]=> string(2) "70" [14]=> string(6) "776478" [15]=> string(6) "832324" [16]=> string(2) "65" [17]=> string(6) "455705" [18]=> string(6) "710640" [19]=> string(2) "47" [20]=> string(5) "76682" [21]=> string(6) "722402" [22]=> string(2) "66" [23]=> string(6) "512396" [24]=> string(6) "863938" [25]=> string(2) "51" [26]=> string(6) "123086" [27]=> string(6) "143396" [28]=> string(2) "80" [29]=> string(7) "2163323" [30]=> string(6) "435239" [31]=> string(2) "67" [32]=> string(6) "560102" [33]=> string(7) "1078055" [34]=> string(2) "47" [35]=> string(5) "80051" [36]=> string(6) "601043" [37]=> string(2) "51" [38]=> string(6) "114870" [39]=> string(6) "715865" [40]=> string(2) "51" [41]=> string(6) "112269" [42]=> string(6) "403800" [43]=> string(2) "57" [44]=> string(6) "219098" [45]=> string(6) "697401" [46]=> string(2) "52" [47]=> string(6) "124179" [48]=> string(6) "599311" [49]=> string(2) "38" [50]=> string(5) "32070" [51]=> string(6) "769359" [52]=> string(2) "44" [53]=> string(5) "59335" [54]=> string(6) "472791" [55]=> string(2) "53" [56]=> string(6) "138904" [57]=> string(6) "591165" [58]=> string(2) "55" [59]=> string(6) "172795" [60]=> string(6) "500981" [61]=> string(2) "33" [62]=> string(5) "19433" [63]=> string(6) "650383" [64]=> string(2) "23" [65]=> string(4) "6979" [66]=> string(6) "552008" [67]=> string(2) "29" [68]=> string(5) "12185" [69]=> string(6) "692439" [70]=> string(2) "25" [71]=> string(4) "7927" [72]=> string(2) "-1" [73]=> string(2) "-1" [74]=> string(2) "-1" [75]=> string(2) "-1" [76]=> string(6) "483773" [77]=> string(1) "6" [78]=> string(6) "362146" [79]=> string(1) "3" [80]=> string(6) "347664" [81]=> string(1) "3" [82]=> string(2) "-1" [83]=> string(2) "-1" [84]=> string(2) "-1" [85]=> string(2) "-1" [86]=> string(2) "-1" [87]=> string(2) "-1" [88]=> string(2) "-1" [89]=> string(2) "-1" [90]=> string(0) "" }