Have some random data that needs to be screened and sorted into a specific format. Sample Data & Current Code below.
All Data is on Sheet2 in Range A1:A10000.
Want data to be screened line by line & copied into Sheet1 in the following format:
ID with Name Following in Same Cell i.e. 0E:57301 Snarley (Note: 0E is consistenty on every data line with a name)
Then next line to have Address with floor folowing i.e.
123 Yarboro Blvd Home Front + Basement + Sub-Basement + Yogic_Den
then onto next ID & repeat for entire range. (Data is random so sometimes Address & floor are already on same line, sometimes not.) Spacing also varies.... might be one blank line between data might be 2 or 3. Sample code will bring data into another sheet but will not be sorted in order needed. Any assistance appreciated. Believe what I need to to loop through the keywords for every line in the data to get into correct order. Also would need to Join some data together i.e. Address & floor when not already on the same line.... Ideas Samples Appreciated
Data Sample:
Turbu-Lockit - Systems
19/04/2012 8:52:01 AM
Slip
Page 1 / 41
Slip
0E:57301 Snarley
Site Level
Location / Location Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57308 Bogo
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57309 Aardvark
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front
0E:57314 Canary
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57328 Kithchen
Entrance level
Gateway / Site Entrance level
123 Yarboro Blvd Home Front + Basement
0E:57330 Bo Didily
Entrance level
Location / Location Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57332 Snapper
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front
Sample Code
Sub Copy_To_Another_Sheet_1()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long
Dim NewSh As Worksheet
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Fill in the search Value
MyArr = Array("0E", "123 Yarboro", "Home Front")
'You can also use more values in the Array
'myArr = Array("@", "
'Add new worksheet to your workbook to copy to
'You can also use a existing sheet like this
'Set NewSh = Sheets("Sheet2")
Set NewSh = Sheets("Sheet1")
With Sheets("Sheet2").Range("A1:C10000")
Rcount = 0
For I = LBound(MyArr) To UBound(MyArr)
'If you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "@"
'Note : I use xlPart in this example and not xlWhole
Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
Rng.Copy NewSh.Range("A" & Rcount)
' Use this if you only want to copy the value
' NewSh.Range("A" & Rcount).Value = Rng.Value
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next I
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
All Data is on Sheet2 in Range A1:A10000.
Want data to be screened line by line & copied into Sheet1 in the following format:
ID with Name Following in Same Cell i.e. 0E:57301 Snarley (Note: 0E is consistenty on every data line with a name)
Then next line to have Address with floor folowing i.e.
123 Yarboro Blvd Home Front + Basement + Sub-Basement + Yogic_Den
then onto next ID & repeat for entire range. (Data is random so sometimes Address & floor are already on same line, sometimes not.) Spacing also varies.... might be one blank line between data might be 2 or 3. Sample code will bring data into another sheet but will not be sorted in order needed. Any assistance appreciated. Believe what I need to to loop through the keywords for every line in the data to get into correct order. Also would need to Join some data together i.e. Address & floor when not already on the same line.... Ideas Samples Appreciated
Data Sample:
Turbu-Lockit - Systems
19/04/2012 8:52:01 AM
Slip
Page 1 / 41
Slip
0E:57301 Snarley
Site Level
Location / Location Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57308 Bogo
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57309 Aardvark
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front
0E:57314 Canary
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57328 Kithchen
Entrance level
Gateway / Site Entrance level
123 Yarboro Blvd Home Front + Basement
0E:57330 Bo Didily
Entrance level
Location / Location Entrance level
123 Yarboro Blvd
Home Front + Basement + Sub-Basement + Yogic_Den
0E:57332 Snapper
Entrance level
Location / Location
Entrance level
123 Yarboro Blvd
Home Front
Sample Code
Sub Copy_To_Another_Sheet_1()
Dim FirstAddress As String
Dim MyArr As Variant
Dim Rng As Range
Dim Rcount As Long
Dim I As Long
Dim NewSh As Worksheet
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
'Fill in the search Value
MyArr = Array("0E", "123 Yarboro", "Home Front")
'You can also use more values in the Array
'myArr = Array("@", "
'Add new worksheet to your workbook to copy to
'You can also use a existing sheet like this
'Set NewSh = Sheets("Sheet2")
Set NewSh = Sheets("Sheet1")
With Sheets("Sheet2").Range("A1:C10000")
Rcount = 0
For I = LBound(MyArr) To UBound(MyArr)
'If you use LookIn:=xlValues it will also work with a
'formula cell that evaluates to "@"
'Note : I use xlPart in this example and not xlWhole
Set Rng = .Find(What:=MyArr(I), _
After:=.Cells(.Cells.Count), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False)
If Not Rng Is Nothing Then
FirstAddress = Rng.Address
Do
Rcount = Rcount + 1
Rng.Copy NewSh.Range("A" & Rcount)
' Use this if you only want to copy the value
' NewSh.Range("A" & Rcount).Value = Rng.Value
Set Rng = .FindNext(Rng)
Loop While Not Rng Is Nothing And Rng.Address <> FirstAddress
End If
Next I
End With
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub