Column match
Solved/Closed
Related:
- Column match
- Music match jukebox - Download - Audio playback
- Partial match excel - Guide
- How to delete column in word - Guide
- Tweetdeck expand column - Guide
- Excel count occurrences of string in column - Guide
2 responses
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
May 17, 2010 at 05:27 AM
May 17, 2010 at 05:27 AM
Can this data be sorted ?
rizvisa1
Posts
4478
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
May 5, 2022
766
May 18, 2010 at 06:52 AM
May 18, 2010 at 06:52 AM
try this. there is a function and a sub. You need to run sub MultiLevelAlign
Sub MultiLevelAlign()
Dim lMaxRowsL As Long
Dim lMaxRowsR As Long
Dim sBCol As String
Dim sJCol As String
Dim vSpaceL As String
Dim vSpaceR As String
Dim valueL As String
Dim valueR As String
sBCol = "B"
sJCol = "J"
lMaxRowsL = Cells(Rows.Count, "A").End(xlUp).Row
lMaxRowsR = Cells(Rows.Count, "I").End(xlUp).Row
With Range(sBCol & "2:" & sBCol & lMaxRowsL)
.FormulaR1C1 = "=LEN(RC1)-LEN(myTrim(RC1,""L""))"
.Copy
.PasteSpecial xlPasteValues
End With
With Range(sJCol & "2:" & sJCol & lMaxRowsR)
.FormulaR1C1 = "=LEN(RC9)-LEN(myTrim(RC9,""L""))"
.Copy
.PasteSpecial xlPasteValues
End With
lMaxRowsL = 2
Do While (lMaxRowsL <= lMaxRowsR)
valueL = Cells(lMaxRowsL, "A")
valueR = Cells(lMaxRowsL, "I")
vSpaceL = Cells(lMaxRowsL, sBCol)
vSpaceR = Cells(lMaxRowsL, sJCol)
If (vSpaceL = vSpaceR) Then
If valueL > valueR Then
Range("I" & lMaxRowsL & ":" & sJCol & lMaxRowsL).Insert Shift:=xlDown
lMaxRowsR = lMaxRowsR + 1
ElseIf valueL < valueR Then
Range("A" & lMaxRowsL & ":" & sBCol & lMaxRowsL).Insert Shift:=xlDown
Else
End If
ElseIf (vSpaceL > vSpaceR) Then
Range("I" & lMaxRowsL & ":" & sJCol & lMaxRowsL).Insert Shift:=xlDown
lMaxRowsR = lMaxRowsR + 1
ElseIf (vSpaceL < vSpaceR) Then
Range("A" & lMaxRowsL & ":" & sBCol & lMaxRowsL).Insert Shift:=xlDown
End If
lMaxRowsL = lMaxRowsL + 1
Loop
Range(sBCol & ":" & sBCol).Clear
Range(sJCol & ":" & sJCol).Clear
End Sub
Function myTrim(myString, Optional trimType As String = "") As String
Select Case UCase(trimType)
Case Is = "L"
myTrim = LTrim(myString)
Case Is = "R"
myTrim = RTrim(myString)
Case Is = ""
myTrim = Trim(myString)
Case Else
myTrim = "#NAME?"
End Select
End Function
May 17, 2010 at 05:46 PM
May 17, 2010 at 05:57 PM
May 17, 2010 at 06:03 PM
May 18, 2010 at 01:31 AM
Could you please upload a sample file with sample data etc on some shared site like https://authentification.site , http://wikisend.com/ , http://www.editgrid.com etc and post back here the link to allow better understanding of how it is now and how you foresee.
May 18, 2010 at 02:03 AM
columns.xls