• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

find move a row up to order

hello SirJB7,


my problem is code below does not work.


ElseIf WorksheetFunction.CountIf(BRange, "YES") > 1 Then

'multiple YES found in col B


With BRange

Set c = .Find("YES")

firstAddress = c.Address

'Check for corresponding C value

If c.Offset(0, 1) <> "YES" Then

Do

Set c = .FindNext

Loop Until c.Offset(0, 1) = "YES" Or c.Address = firstAddress

End If

End With

Set CutRow = c.EntireRow

Else

'YES only found in col C

Set CutRow = CRange.Find("YES").EntireRow

End If


It is meant for search another YES is present or not, but it only stops after getting one YES in col D.
 
Hi, sparcle!

This is a large topic (53 posts and 5 voices, being mine none of the relevants). Would you please post a brief summary of what needed, what does actually do -the very main issue- and if with your uploaded file it's enough to check it? So I'd avoid reading all previous 50+ comments and get right to the point. Thanks you.

Regards!
 
hello sir,

Thank you for response.

I briefly describe what is need.


In my uploaded worksheet,


I want to move the cell up to order basis on some condition, in D col if one YES is found & then it move up order.If there is multiple YES found then which correspondent E col is YES will move up to order, otherwise the first YES in col D will move up.


If there is no YES in col D & YES in col E then first YES in col E will move up.
 
@SirJB7,

Hello sir,


I briefly describe it, my problem is the code only find out first YES in col D & move it up,it does go further as written in code,So sir could you find out where is bug there.
 
Hi, sparcle!


I see you've made many changes to the code provided by Luke M which I won't check, just focus on you uploaded file.

First of all, your macro crashes if a cell from rows 5:13 isn't selected before running it.

Secondly, the procedure works Ok, as it moves original row 8 to (before) row 6, the address of xSelect range which starts at row 6 and not at row 5 because of the exclusion of rows with "X" in column K.

So I don't understand what it isn't working. Could you please elaborate a bit more from a different viewpoint or upload any other file more exemplary? Thank you.


Regards!
 
thank you sir for your response.


i will elaborate it.


sir can you check it through team viewer.


sir in code there is a timestamp which store I value of selected row. range is those rows whose timestamp value of col G. If i select any cell of A11 row then range will be those G cells whose time value is <= to I11 & its correspondent k cell not mark as X.


Then when run macro cell will move up to order as per condition.


The cell move up to order basis on some condition, in D col if one YES is found & then it move up order.If there is multiple YES found then which correspondent E col is YES will move up to order, otherwise the first YES in col D will move up.


If there is no YES in col D & YES in col E then first YES in col E will move up.


But my problem is the code only find out first YES in col D & move it up,it does go further as written in code
 
Hi, sparcle!


I think the code was intended to move up just first row with YES in column D after all not "X" in K, so it wouldn't be a minor change to adapt it for all cells in D. Before doing that, I was wondering if sorting the range by column K descendent (first "X", then blanks", column D descendent (first YES, then NO), column E descendent (first YES, then NO), wouldn't achieve the goal. What do you think?


Regards!
 
sir only that cell will move up the order, if we descendent the cells then it will replace the originality.


in my workbook A11 row has both YES in col D & E so it move up the order to below the cell A5 row then i have to mark it X so that next cell with condition fulfill will move up the order.
 
I think sir problem is between these code & need some modification.


If WorksheetFunction.CountIf(Union(BRange, CRange), "YES") = 0 Then

'Do nothing

Exit Sub

ElseIf WorksheetFunction.CountIf(BRange, "YES") = 1 Then

'only 1 YES found

Set CutRow = BRange.Find("YES").EntireRow

ElseIf WorksheetFunction.CountIf(BRange, "YES") > 1 Then

'multiple YES found in col B


With BRange

Set c = .Find("YES")

firstAddress = c.Address

'Check for corresponding C value

If c.Offset(0, 1) <> "YES" Then

Do

Set c = .FindNext

Loop Until c.Offset(0, 1) = "YES" Or c.Address = firstAddress

End If

End With

Set CutRow = c.EntireRow

Else

'YES only found in col C

Set CutRow = CRange.Find("YES").EntireRow

End If
 
Trying to recall what was going on and putting all the changes that you've requested into a single, macro, I think this will do what you want.

[pre]
Code:
Sub ReorderRows()
Dim xSelect As Range
Dim BRange As Range
Dim CRange As Range
Dim c As Range
Dim firstAddress As String
Dim TimeStamp As Double
Dim DTable As Range
Dim CutRow As Range

TimeStamp = Cells(ActiveCell.Row, "G").Value
Set DTable = Selection.CurrentRegion

'Delete this line if AutoFilter is already active
DTable.AutoFilter

'Filter down to just the relevant info based on col G
ActiveSheet.Range("A1").AutoFilter Field:=7, Criteria1:= _
"<=" & TimeStamp
ActiveSheet.Range("A1").AutoFilter Field:=11, Criteria1:= _
"<>X"

'New Line
Set xSelect = DTable.Offset(1, 0).Resize(DTable.Rows.Count - 1, _
DTable.Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow

'Yes's are in col D and E
Set BRange = Intersect(xSelect, Range("D:D"))
Set CRange = Intersect(xSelect, Range("E:E"))

If Application.WorksheetFunction.CountIf(Union(BRange, CRange), "YES") = 0 Then
'Do nothing
Exit Sub
ElseIf WorksheetFunction.CountIf(BRange, "YES") = 1 Then
'only 1 YES found
Set CutRow = BRange.Find("YES").EntireRow
ElseIf WorksheetFunction.CountIf(BRange, "YES") > 1 Then
'multiple YES found in col B

With BRange
Set c = .Find("YES")
firstAddress = c.Address
'Check for corresponding C value
If c.Offset(0, 1) <> "YES" Then
Do
Set c = .FindNext
Loop Until c.Offset(0, 1) = "YES" Or c.Address = firstAddress
End If
End With
Set CutRow = c.EntireRow
Else
'YES only found in col C
Set CutRow = CRange.Find("YES").EntireRow
End If

'Unfilter
ActiveSheet.ShowAllData

'Delete this line if AutoFilter already activ4
DTable.Range("A1").AutoFilter

'Mark the row
CutRow.Cells(1, "K").Value = "X"
CutRow.Cut
On Error Resume Next 'do nothing if row was already at top
xSelect.Cells(1, 1).Insert Shift:=xlDown
On Error GoTo 0
Application.CutCopyMode = False
End Sub
[/pre]
 
@Luke M,

Hello sir,


Again a small flaw was found.


if i inserted a row then it gave problem in sorting.

Here in uploaded file when i inserted row 14 it gives problem.I figure out that due to insert of May month after june month date it gives error.The same thing if i inserted after row 9 it works fine.

Is there any problem in date format in my excel sheet.


http://www.2shared.com/file/vD0tkYeI/1_online.html
 
Boo. Countif won't work on discontinuous ranges. Time to use a bigger hammer!

Sub ReorderRows()
Dim xSelect As Range
Dim BRange As Range
Dim CRange As Range
Dim c As Range
Dim firstAddress As String
Dim TimeStamp As Double
Dim DTable As Range
Dim CutRow As Range

TimeStamp = Cells(ActiveCell.Row, "G").Value
Set DTable = Selection.CurrentRegion

'Delete this line if AutoFilter is already active
DTable.AutoFilter

'Filter down to just the relevant info based on col G
ActiveSheet.Range("A1").AutoFilter Field:=7, Criteria1:= _
"<=" & TimeStamp
ActiveSheet.Range("A1").AutoFilter Field:=11, Criteria1:= _
"<>X"

'New Line
Set xSelect = DTable.Offset(1, 0).Resize(DTable.Rows.Count - 1, _
DTable.Columns.Count).SpecialCells(xlCellTypeVisible).EntireRow

'Yes's are in col D and E
Set BRange = Intersect(xSelect, Range("D:D"))
Set CRange = Intersect(xSelect, Range("E:E"))

If FindAll(Union(BRange, CRange), "YES") Is Nothing Then
'Do nothing
GoTo GetOut
ElseIf FindAll(BRange, "YES").Count = 1 Then
'only 1 YES found
Set CutRow = BRange.Find("YES").EntireRow
ElseIf FindAll(BRange, "YES").Count > 1 Then
'multiple YES found in col B

With BRange
Set c = .Find("YES")
firstAddress = c.Address
'Check for corresponding C value
If c.Offset(0, 1) <> "YES" Then
Do
Set c = .FindNext
Loop Until c.Offset(0, 1) = "YES" Or c.Address = firstAddress
End If
End With
Set CutRow = c.EntireRow
Else
'YES only found in col C
Set CutRow = CRange.Find("YES").EntireRow
End If

'Unfilter
ActiveSheet.ShowAllData

'Mark the row
CutRow.Cells(1, "K").Value = "X"
CutRow.Cut
On Error Resume Next 'do nothing if row was already at top
xSelect.Cells(1, 1).Insert Shift:=xlDown
On Error GoTo 0

GetOut:
'Delete this line if AutoFilter already activ4
DTable.Range("A1").AutoFilter
Application.CutCopyMode = False
End Sub

'Function from Chip Pearson
Function FindAll(SearchRange As Range, _
FindWhat As Variant, _
Optional LookIn As XlFindLookIn = xlValues, _
Optional LookAt As XlLookAt = xlWhole, _
Optional SearchOrder As XlSearchOrder = xlByRows, _
Optional MatchCase As Boolean = False, _
Optional BeginsWith As String = vbNullString, _
Optional EndsWith As String = vbNullString, _
Optional BeginEndCompare As VbCompareMethod = vbTextCompare) As Range
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FindAll
' This searches the range specified by SearchRange and returns a Range object
' that contains all the cells in which FindWhat was found. The search parameters to
' this function have the same meaning and effect as they do with the
' Range.Find method. If the value was not found, the function return Nothing. If
' BeginsWith is not an empty string, only those cells that begin with BeginWith
' are included in the result. If EndsWith is not an empty string, only those cells
' that end with EndsWith are included in the result. Note that if a cell contains
' a single word that matches either BeginsWith or EndsWith, it is included in the
' result. If BeginsWith or EndsWith is not an empty string, the LookAt parameter
' is automatically changed to xlPart. The tests for BeginsWith and EndsWith may be
' case-sensitive by setting BeginEndCompare to vbBinaryCompare. For case-insensitive
' comparisons, set BeginEndCompare to vbTextCompare. If this parameter is omitted,
' it defaults to vbTextCompare. The comparisons for BeginsWith and EndsWith are
' in an OR relationship. That is, if both BeginsWith and EndsWith are provided,
' a match if found if the text begins with BeginsWith OR the text ends with EndsWith.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Dim FoundCell As Range
Dim FirstFound As Range
Dim LastCell As Range
Dim ResultRange As Range
Dim XLookAt As XlLookAt
Dim Include As Boolean
Dim CompMode As VbCompareMethod
Dim Area As Range
Dim MaxRow As Long
Dim MaxCol As Long
Dim BeginB As Boolean
Dim EndB As Boolean

CompMode = BeginEndCompare
If BeginsWith <> vbNullString Or EndsWith <> vbNullString Then
XLookAt = xlPart
Else
XLookAt = LookAt
End If

' this loop in Areas is to find the last cell
' of all the areas. That is, the cell whose row
' and column are greater than or equal to any cell
' in any Area.

For Each Area In SearchRange.Areas
With Area
If .Cells(.Cells.Count).Row > MaxRow Then
MaxRow = .Cells(.Cells.Count).Row
End If
If .Cells(.Cells.Count).Column > MaxCol Then
MaxCol = .Cells(.Cells.Count).Column
End If
End With
Next Area
Set LastCell = SearchRange.Worksheet.Cells(MaxRow, MaxCol)

On Error GoTo 0
Set FoundCell = SearchRange.Find(what:=FindWhat, _
after:=LastCell, _
LookIn:=LookIn, _
LookAt:=XLookAt, _
SearchOrder:=SearchOrder, _
MatchCase:=MatchCase)

If Not FoundCell Is Nothing Then
Set FirstFound = FoundCell
Do Until False ' Loop forever. We'll "Exit Do" when necessary.
Include = False
If BeginsWith = vbNullString And EndsWith = vbNullString Then
Include = True
Else
If BeginsWith <> vbNullString Then
If StrComp(Left(FoundCell.Text, Len(BeginsWith)), BeginsWith, BeginEndCompare) = 0 Then
Include = True
End If
End If
If EndsWith <> vbNullString Then
If StrComp(Right(FoundCell.Text, Len(EndsWith)), EndsWith, BeginEndCompare) = 0 Then
Include = True
End If
End If
End If
If Include = True Then
If ResultRange Is Nothing Then
Set ResultRange = FoundCell
Else
Set ResultRange = Application.Union(ResultRange, FoundCell)
End If
End If
Set FoundCell = SearchRange.FindNext(after:=FoundCell)
If (FoundCell Is Nothing) Then
Exit Do
End If
If (FoundCell.Address = FirstFound.Address) Then
Exit Do
End If

Loop
End If

Set FindAll = ResultRange

End Function
 
woooo............


Its really a huge one.


'Function from Chip Pearson

After this line all code are go over my head.


I think i am asking a little, but seems am asking a lot.


I can only say thank you sir, no other words.
 
Thankfully, I didn't have to write that last part. Comes from MVP Chip Pearson at:

http://www.cpearson.com/excel/findall.aspx


But yeah, had to find a new way to do a "countif" style formula.
 
Sir,

I just came across a article about how to Undo Changes Done By Excel VBA.

Here is referance

http://www.jkp-ads.com/Articles/UndoWithVBA00.asp


Is it possible to use it in all VBA to undo things that already happened.


sir thank you for your kindly support.
 
<p>Shear stress is created from the teeth of metal gears being applied to the metal face of other gears in a parallel form.? These gear faces are under the full force of the engine's power in a manual transmission or differential.? These components translate this power to the wheels at the desired speed depending on how the gears are applied.? In order to protect the faces of these gears over time, gear oil must act as a lubricant and provide protection to these metal surfaces.? It's viscosity rating is normally higher than that of regular motor oil, and it's molecular, strength level must stay consistent between drain intervals.? If manual transmission or differential oil can not withstand these extreme pressures and temperatures from shear stress, pitting and scoring on the faces of these metal gears will occur.? This wear will create metal flake and fluid contamination which will only cause more wear.? beats by dr dre solo red The cycle will continue to repeat itself until part failure will ultimately occur.? Synthetic manual transmission and differential oil lowers the chance of this occurrence because of it's powerful properties.</p>

<p>Conventional,http://www.buddykut.com/blog_entry.php?user=sdhwbb578d&blogentry_id=72198, petroleum based oils break down quickly from shear stress and the extreme temperatures caused by gear frictions.? Their irregular molecular structure created in the refining process can not beats solo hd red headphones withstand these conditions well between drain intervals.? They thin quickly and allow the metal faces of gears to grind on one another.? Synthetic fluids are created in a laboratory to possess more specific properties such as viscosity and a uniform molecular structure.? Because it is chemically engineered for a specific composition, the power of synthetic manual transmission and differential oil is much better suited for these purposes.? It withstands these extreme stresses, red beats solo hd temperatures,http://immenso-media.com/forums/topic.php?id=67660&replies=2#post-103710, and frictions better than traditional oils.? These synthetic fluids also contain special,http://edgewerks.com/forums/topic.php?id=24679&replies=1#post-24918, high pressure and anti-wear additives that protect and clean these vital metal parts.? These additive rich, synthetic fluids cope better under the intense, gear pressures present in manual transmissions and differentials.</p>

<p>Although just as helpful and necessary for protection in ordinary vehicles, synthetic manual transmission and differential oil is especially helpful in those used for racing, hauling, and towing. ?These applications create red monster beats
http://http://beatsdresolos.blogspot.com/2012/07/red-monster-beats.html the largest loads and stresses on the gears of these components.? The financial savings created from better protecting these components in both regular applications and those used more for specific purposes is clearly demonstrated in longer drain intervals, fewer part repairs, and better performance.? Amsoil, one of the leading producers of synthetic oils, offers a wide range of synthetic manual transmission and differential red beats by dre headphones
http://http://beatsdresolos.blogspot.com/2012/07/red-beats-by-dre-headphones.html oils at competitive prices, including their Synthetic Manual Synchromesh Fluid which can be used in all automotive applications requiring synchromesh transmission fluid.? Without question or exception, the power of synthetic protection in manual transmissions and differentials proves superior to traditional fluids every time.</p>
 
Crackle cheap beats for sale effect manicure <p>One of the latest trends in club beats for sale nail art is the crackle effect also known as the cracked effect. A French manicure is not the only option for women anymore. Many new unique designs are always coming reggaeton beats for sale up,http://mysocial.altervista.org/activity/p/24276/, enabling women to make different personal style statements. Celebrities have helped in making this type of nail design all the rage right now. </p> <p>Many brands are coming beats with hooks for salehttp://http://studiobeatsdr.blogspot.com/2012/07/beats-with-hooks-for-sale.html up with the shatter or crackle nail polish. This type of nail polish gives the desired effect. This effect is obtained by painting the nail with the color of your choice,http://www.legalresources.co.za/members/sdhwbb578d/activity/p/77187/, allowing the nail to dry and then applying a special top coat that give the desired cracked effect. So, all you need is a clear base coat,http://www.acrossthepondnj.com/forums/topic.php?id=1203&replies=1#post-1289, colored nail polish and shatter nail polish. Keep in mind that the colors need to match or else dr dre beats for salehttp://http://studiobeatsdr.blogspot.com/2012/07/dr-dre-beats-for-sale.html it will not look as good as you want it to.</p>
 
@Luke M

Hello sir,

Last hurdle in front me.

In my workbook, i want to add another criteria that relevant data filter in ascending order. Adding in these codes.


'Filter down to just the relevant info based on col G

ActiveSheet.Range("A1").AutoFilter Field:=7, Criteria1:= _

"<=" & TimeStamp

ActiveSheet.Range("A1").AutoFilter Field:=11, Criteria1:= _

"<>X"


Reason for doing that row 8 & 9 has equal condition but row 9 has minimum date value.So if i can filter it in ascending order then i think job will be done.


http://www.2shared.com/file/8ckVr-6J/11a.html
 
Add this bit of code after the first two filters. I'm also assuming that by "ascending" you actually meant in date order (Jan, Feb, March) which XL thinks of as descending.

[pre]
Code:
With ActiveSheet.AutoFilter.Sort
.SortFields.Clear
.SortFields.Add Key:=Range _
("G1"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
.Apply
End With
[/pre]
 
Back
Top