0
我有一個列名稱作爲「驗證」,但列號保持更改。我怎樣才能找到這個名稱的名稱,並將其作爲範圍。通過選擇列名作爲範圍來添加Excel公式的VBA
當前,下面是我正在使用的宏,它檢查列M併爲所有單元格添加公式,如果列M不爲空。
我的新的期望是,
- 見M列,如果有細胞的值作爲「BLM」 &「CFG」,然後通過找到列名「驗證」添加了Excel 式爲那些具有 那單元格值爲「BLM」&「CFG」,如果空白則跳過。
- 更改所有這些公式單元格值
Sub test_macro()
Dim sFormula As String
Dim rng As Range
Dim ws2 As Worksheet
sFormula = "=IF(IFERROR(VLOOKUP(RC[-11],'Service ID Master List'!C[-11],1,0),""Fail"")=""Fail"",""Check SESE_ID"","""")&IF(IFERROR(VLOOKUP(RC[-9],Rules!C[-13],1,0),""Fail"")=""Fail"","" | Check SESE_RULE"","""")&IF(TRIM(RC[-5])="""","""",IF(IFERROR(VLOOKUP(RC[-5],Rules!C[-13],1,0),""Fail"")=""Fail"","" | Check SESE_RULE_ALT"",""""))&IF(RC[-7]=""TBD"","" | Check SEPY_ACCT_CAT"","""")"
Set ws2 = ActiveSheet
With ws2
Set rng = .Range("M2")
Set rng = .Range(rng, .Cells(.Rows.Count, rng.Column).End(xlUp))
End With
rng.SpecialCells(xlCellTypeConstants).Offset(0, 1).FormulaR1C1 = sFormula
'changing formulas in values
Columns("N:N").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("N1").Select
Application.CutCopyMode = False
End Sub
不完全,但我可能能夠做到這一點,可能是我沒有提及的要求非常好,無論如何。 – Chito 2014-10-09 00:37:17