Forum Discussion
hrh_dash
Oct 31, 2022Iron Contributor
Macro to include an array formula into an existing do loop
Hi all, i would like to insert this array formula into an existing do loop. Excel formula will be as follows: A2 = TRIM(LEFT(A2,MIN(FIND({0,1,2,3,4,5,6,7,8,9},A2&"0123456789"))-1)) Code as...
- Nov 02, 2022
You can use Evaluate only for a single cell, not for a multi-cell range. Does this work for you?
Sub testt() Dim ws As Worksheet Dim lastRow As Long Dim rng As Range Set ws = ThisWorkbook.Sheets("Sheet2") lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row Set rng = ws.Range("A2:A" & lastRow) With rng.Offset(0, 4) .Formula = "=TRIM(LEFT(" & rng.Address & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9}," & rng.Address & "&""0123456789""))-1))" .Value = .Value End With End Sub
HansVogelaar
Nov 02, 2022MVP
You can use Evaluate only for a single cell, not for a multi-cell range. Does this work for you?
Sub testt()
Dim ws As Worksheet
Dim lastRow As Long
Dim rng As Range
Set ws = ThisWorkbook.Sheets("Sheet2")
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
Set rng = ws.Range("A2:A" & lastRow)
With rng.Offset(0, 4)
.Formula = "=TRIM(LEFT(" & rng.Address & ",MIN(FIND({0,1,2,3,4,5,6,7,8,9}," & rng.Address & "&""0123456789""))-1))"
.Value = .Value
End With
End Sub
hrh_dash
Nov 03, 2022Iron Contributor
, thank you! Much appreciated!