
Sub correggiformula()
Dim risultato As String
valore = Range("E10").Value
form = Range("K10").Value
Range("P16").Select
Cells.Replace what:="A0", replacement:="", lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Cells.Replace what:="ABS", replacement:="ASS", lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Cells.Replace what:=valore, replacement:=form, lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Range("K16").Value = "=" & Range("p16").Value
End Sub
|
Option Explicit
Sub correggiformula()
Dim risultato As String
i = 1
valore = Range("i, 5").Value
form = Range("i, 11").Value
For i = Righe To 1 Step -1
Cells(i, 16).Select
If Selection.Value > 0 Then
Cells.Replace what:="A0", replacement:="", lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Cells.Replace what:="ABS", replacement:="ASS", lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Cells.Replace what:=valore, replacement:=form, lookat:=xlPart _
, searchorder:=xlByRows, MatchCase:=False, searchformat:=False, _
ReplaceFormat:=False
Range("i, 11").Value = "=" & Range("i, 16").Value
Next i
End Sub
|
Sub correggiformula_VF()
Dim re As Object, ma As Object
Dim tabella As Range, ac As Range, c As Range, c1 As Range
Dim fA As String, s As String
Dim ur As Long
Sheets("Foglio 2").Select
ur = Range("A1").CurrentRegion.Rows.Count
Set tabella = Range("P2..P" & ur)
Set re = CreateObject("VBScript.RegExp")
re.Global = True
re.IgnoreCase = False 'ignore case
re.Pattern = "A0d{4}"
For Each c In tabella.SpecialCells(xlCellTypeConstants)
If re.test(c) Then
s = c
For Each ma In re.Execute(c)
If ma <> "" Then
Set c1 = tabella.Offset(, -11).Find(Mid(ma, 3), lookat:=xlWhole, LookIn:=xlValues)
s = Replace(s, ma, c1.Offset(, 6))
End If
Next
Cells(c.Row, "K") = Evaluate(s)
End If
Next
MsgBox "Finito", vbInformation
End Sub
|
s = Replace(s, ",", ".")A me non succedeva perchè nell'esempio il separatore dei numeri decimali è il punto. Certo che le espressioni devono essere perfette e valutabili altrimenti si produce errore.
Cells(c.Row, "K") = Evaluate(s)
