help with column looping

new2vba

Board Regular
Joined
Aug 15, 2006
Messages
146
i have multiple columns with a name followed by five #'s as such:

Name
#1
#2
#3
#4
#5

i'm want to loop through each column, and when criteria are met (ex:#4>#1), copy that column to another location and sort the numbers. i have a problem thinking in vba code, and i can't figure out how to code this logic:

for each column b to e, if row 5>row2 then....

the copy and sort which follows i think i got. Any ideas?
 
I just looked at your file. Apparantly you missed the changes I made. Delete the code you have and paste this one. It worked fine in your workbook.
Code:
Sub Compare_Entries() 
Dim Tcell As Range 
Dim Mycell As Range 

Range("A11:IV65536").ClearContents 

For Each Tcell In Range("A1", Range("A1").End(xlToRight)) 
    If Tcell.Offset(5).Value < Tcell.Offset(3).Value Then 
        Select Case Range("A1").Offset(10).Value 
                Case "" 
                    Set Mycell = Range("A1").Offset(10) 
                Case Is <> "" 
                    Set Mycell = Range("IV11").End(xlToLeft).Offset(0, 1) 
        End Select 

        Tcell.Resize(6).Copy Mycell 
        Mycell.Offset(1).Resize(6).Sort Key1:=Mycell.Offset(1), Order1:=xlAscending, Header:=xlNo, _ 
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom 
        
    End If 
Next Tcell 

End Sub
Should work.

Mac
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
i dont know how i missed your changes , but i think this is working. thanks again - have a great night
 
Upvote 0
One more thing. If you want to maintain your formatting use this one:
Code:
Sub Compare_Entries()
Dim Tcell As Range
Dim Mycell As Range

Range("A11:IV65536").ClearContents

For Each Tcell In Range("A1", Range("A1").End(xlToRight))
    If Tcell.Offset(5).Value < Tcell.Offset(3).Value Then
        Select Case Range("A1").Offset(10).Value
                Case ""
                    Set Mycell = Range("A1").Offset(10)
                Case Is <> ""
                    Set Mycell = Range("IV11").End(xlToLeft).Offset(0, 1)
        End Select

        Tcell.Resize(6).Copy
        Mycell.PasteSpecial xlPasteValues
        Mycell.Offset(1).Resize(6).Sort Key1:=Mycell.Offset(1), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        
    End If
Next Tcell

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top