Here's a commented version of the macro to help with your examination:
Option Explicit
Sub ImportDeviceInfo()
Dim LR As Long, Rw As Long, NR As Long
Dim wsIN As Worksheet, wsOUT As Worksheet
Dim Device As String, IP As String, Unit As String, MyArr As Variant
Set wsOUT = ThisWorkbook.Sheets("DataTable") 'destination sheet
Set wsIN = ThisWorkbook.Sheets("Incoming") 'source data
NR = wsOUT.Range("A" & Rows.Count).End(xlUp).Row + 1 'next empty row on destination sheet
LR = wsIN.Range("A" & Rows.Count).End(xlUp).Row 'last used row of source data
Application.ScreenUpdating = False 'speed up macro by not updating the screen
For Rw = 1 To LR 'evaluate one row at a time
With wsIN.Range("A" & Rw) 'looking in column A of that row
If Len(.Value) > 0 Then 'skip this if the cell is blank
If InStr(.Value, "):") > 0 Then 'if a colon exists in the text string...
MyArr = Split(Trim(.Value), " ") '...split the string
Device = MyArr(0) '...store the Device Name for use later
IP = Replace(Replace(MyArr(1), "(", ""), "):", "") '...store the IP, clean out the unneeded characters
ElseIf InStr(.Value, "Unit") > 0 Then 'if "unit" exists in the text string...
Unit = Trim(Replace(.Value, "Unit", "")) '...store the unit number for use later
ElseIf InStr(.Value, "serial number") > 0 Then 'if "serial number" exists in the test string...
wsOUT.Range("A" & NR).Value = Device '...write the device name into empty row
wsOUT.Range("B" & NR).Value = IP '...write the IP into the empty row
wsOUT.Range("C" & NR).Value = Unit '...write the Unit number into the empty row
wsOUT.Range("D" & NR).Value = Trim(Mid(.Value, InStr(.Value, "number:") + 8, 20)) '...write out the serial number clean out the unneeded characters
NR = NR + 1 'increment to next empty row
End If
End If
End With
Next Rw
Application.ScreenUpdating = True 'update the screen one time at the end
wsOUT.Columns.AutoFit 'clean up the columns
End Sub
If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
Bookmarks