vba自动公式

Private Sub CommandButton1_Click()

Dim Str, formular, sheetName As String
Dim splitArray
Dim to_cell_with_formula, curVal
Str = Sheets("setting").Cells(1, 1).Value
  splitArray = Split(Str, "-->")
  sheetName = splitArray(0)
  to_cell_with_formula = splitArray(1)
  formular = splitArray(2)
 
  
 ' For n = LBound(Val) To UBound(Val)
 '   MsgBox Val(n)
 ' Next
Dim sheet_row, rownum As Integer


 With Sheets(sheetName)
 sheet_row = .Range("A65535").End(xlUp).Row
 For rownum = 2 To sheet_row
 curVal = to_cell_with_formula & CStr(rownum)
 .Range(curVal).FormulaR1C1 = formular
 If .Range(curVal).Value <> "same" Then
 
 .Range(curVal).Interior.ColorIndex = 35
 End If
 
 Next rownum
 

 End With
 
End Sub



datasheet-->J-->=if((abs(RC[-2]-RC[-1])/RC[-4])<0.2,"same",(abs(RC[-2]-RC[-1])/RC[-4]))

你可能感兴趣的:(VBA)