Thank you for the response.
The source needs to be read only, are you suggesting to copy over the columns into my new file, and then add a helper column?
If so, then I guess I can create a macro to copy over all columns needed from data.xlsm to Tally.xlsm, then another to simply strip the numbers from the text.
Example of a macro I copied and tested to remove text from numbers here:
Sub KillNonNumbers()
Dim rng1 As range
Dim rngArea As range
Dim lngRow As Long
Dim lngCol As Long
Dim lngCalc As Long
Dim objReg As Object
Dim x()
On Error Resume Next
Set rng1 = Application.InputBox("Select range for the replacement of non-number", "User select", Selection.Address, , , , , 8)
If rng1 Is Nothing Then Exit Sub
On Error GoTo 0
'See Patrick Matthews excellent article on using Regular Expressions with VBA
Set objReg = CreateObject("vbscript.regexp")
objReg.Pattern = "[^\d]+"
objReg.Global = True
'Speed up the code by turning off screenupdating and setting calculation to manual
'Disable any code events that may occur when writing to cells
With Application
lngCalc = .Calculation
.ScreenUpdating = False
.Calculation = xlCalculationManual
.EnableEvents = False
End With
'Test each area in the user selected range
'Non contiguous range areas are common when using SpecialCells to define specific cell types to work on
For Each rngArea In rng1.Areas
'The most common outcome is used for the True outcome to optimise code speed
If rngArea.Cells.Count > 1 Then
'If there is more than once cell then set the variant array to the dimensions of the range area
'Using Value2 provides a useful speed improvement over Value. On my testing it was 2% on blank cells, up to 10% on non-blanks
x = rngArea.Value2
For lngRow = 1 To rngArea.Rows.Count
For lngCol = 1 To rngArea.Columns.Count
'replace the leading zeroes
x(lngRow, lngCol) = objReg.Replace(x(lngRow, lngCol), vbNullString)
Next lngCol
Next lngRow
'Dump the updated array sans leading zeroes back over the initial range
rngArea.Value2 = x
Else
'caters for a single cell range area. No variant array required
rngArea.Value = objReg.Replace(rngArea.Value, vbNullString)
End If
Next rngArea
'cleanup the Application settings
With Application
.ScreenUpdating = True
.Calculation = lngCalc
.EnableEvents = True
End With
Set objReg = Nothing
End Sub
Source is found here: stackoverflow.com/questions/27651997/vba-to-edit-excel-column-of-data
Of course, your helper column looks like a great way to use native formulas when the extraction is similar, and may be a preferred method.
Strikethrough was used to show a cancelled order existed, but the history was still needed.
If data was copied, I could check for strikethrough and multiply the number with -1 and sum as needed, but will need a function to do this.
Would this be an appropriate method?
Bookmarks