Standard disclaimer: I'm not a VBA regular. I rarely work with Excel so most of my code is gleaned from more qualified folks, hopefully like you.
I'm writing a macro (or a series of them which I'll combine later) to calculate a due date based on invoice date and terms (expressed as NET10). Everything is running well except this critical part of extracting the numerical value. This code is beyond me once it gets to the InputBox which I'd be happy to replace with a selection of a specific column since it will always be the same one.
It works... eventually. When running this macro excel goes into a (not responding) state for a period of several minutes before pushing out the results. The results are correct but I can't explain why it struggles, my cpu doesn't exceed 20% so it's not lack of processor power.
So my question is twofold:
Can this be written in a way that doesn't bog down excel?
and
Is it possible to replace the selection with an assigned selection like something that is working in other sections: Range("D1:D" & LastRow)
(yes, I would have to declare LastRow Variable)
Sub GetNumbers()
Dim xRegEx As Object
Dim xRg As Range
Dim xCell As Range
Dim xTxt As String
On Error Resume Next
xTxt = ActiveWindow.RangeSelection.Address
Set xRg = Application.InputBox("please select range:", "Test", xTxt, , , , , 8)
If xRg Is Nothing Then Exit Sub
Set xRegEx = CreateObject("VBScript.RegExp")
With xRegEx
.Pattern = "\D+"
.IgnoreCase = True
.Global = True
End With
xRg.NumberFormat = "General"
For Each xCell In xRg
xCell.Value = xRegEx.Replace(xCell.Value, "")
Next
Set xRegEx = Nothing
End Sub
while I have the floor, one more question:
Is it better to write multiple macros and call them in a single one or actually write them as one?
Thanks for this forum helping get me this far.
Bookmarks