Results 1 to 1 of 1

Code selects entire rows upto one range and same code selects only columns for other.

Threaded View

sriharigk Code selects entire rows upto... 07-09-2012, 05:19 AM
  1. #1
    Registered User
    Join Date
    07-09-2012
    Location
    Bangalore,India
    MS-Off Ver
    Excel 2007
    Posts
    1

    Code selects entire rows upto one range and same code selects only columns for other.

    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
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1