Hi
I am stuck up with a problem. I have used some of the code I got from this forum. In the excel sheet attached there are two set of ranges ...range named 45 and the range named 25. If if run this code...for the range 45, the codes shifts the entire range. and for the range 25..it selects only the column. I want to shift entire range as it happens for range 45. Kindly help.
Code goes like this
Sub align_2()
n = 2
lastrow = Application.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
While (n <= lastrow)
If (ActiveSheet.Cells(n, 2).Value > ActiveSheet.Cells(n, 8).Value) Then
Set Rng = Worksheets(1).Range("G" & n)
Set RngEnd = Worksheets(1).Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Worksheets(1).Range(Rng, RngEnd)
Worksheets(1).Range(Rng, RngEnd).Select
For R = 1 To Rng.Rows.Count
If Rng.Item(R, 1) = "" And R <> 1 Then
Set Rng = Rng.Resize(R - 1, 5)
Rng.Select
Exit For
End If
Next R
'ActiveSheet.Range("G" & n & ":j750").Select
Selection.Cut
ActiveSheet.Range("G" & n + 1).Select
ActiveSheet.Paste
ElseIf (ActiveSheet.Cells(n, 1).Value < ActiveSheet.Cells(n, 7).Value) Then
Set Rng = Worksheets(1).Range("A" & n)
Set RngEnd = Worksheets(1).Cells(Rows.Count, Rng.Column).End(xlUp)
If RngEnd.Row < Rng.Row Then Exit Sub Else Set Rng = Worksheets(1).Range(Rng, RngEnd)
Worksheets(1).Range(Rng, RngEnd).Select
For R = 1 To Rng.Rows.Count
If Rng.Item(R, 1) = "" And R <> 1 Then
Set Rng = Rng.Resize(R - 1, 5)
Rng.Select
Exit For
End If
Next R
'ActiveSheet.Range("A" & n & ":E750").Select
Selection.Cut
ActiveSheet.Range("A" & n + 1).Select
ActiveSheet.Paste
End If
n = n + 1
Wend
End Sub
Bookmarks