Sometimes, you may encounter a job on reversing the domain name by notation as below screenshot shown, do you have any tricks to quickly solve it? In this article, I introduce two methods to quickly handle it.
Here is a macro code that can help you, please do as follow in Excel:
1. Press Alt + F11 keys to enable the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, copy and paste the code to the blank script.
VBA: Reverse domain name by notation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
Sub Reverse() 'UpdatebyExtendoffice2017115 Dim xArr() As String Dim xSplitStr As String Dim xVal As String Dim xRg As Range Dim xCell As Range Dim xIndex As Long On Error Resume Next Set xRg = Application.InputBox( "Select cells:" , "KuTools For Excel" , Selection.Address, , , , , 8) If xRg Is Nothing Then Exit Sub Application.ScreenUpdating = False xSplitStr = "." For Each xCell In xRg If InStr(xCell.Value, xSplitStr) = 0 Then GoTo xBreak xVal = "" xArr = Split(xCell.Value, xSplitStr) xIndex = UBound(xArr) xVal = xArr(xIndex) Do xIndex = xIndex - 1 xVal = xVal & xSplitStr & xArr(xIndex) Loop While xIndex > 0 xCell.Value = xVal xBreak: Next Application.ScreenUpdating = True End Sub |
3. Press F5 key, a dialog pops out to remind you select a range to work.
4. Click OK.