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?
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
I am intrigued. Can you click the E-Mail button at the botton of this post and send me the workbook or a harmless copy of it?
 
Upvote 0
:LOL: You're going to laugh at this one.

Scroll all the way to the right of your workbook. You'll see a lot of data there (Probably from our earlier, failed attempts). Delete this and the code will run fine.

Let me know if it works.

Mac
 
Upvote 0
yeah that figures :oops: :x
you've been a great help...im going to play with this for a while and try to add some criteria to what youve written.

thanks,

jon
 
Upvote 0
mac,

im trying to change the code as such - i want to copy the columns that meet the criteria - side by side - just like we did, but i want it to start copying to column "A" every time it is run. now it keeps adding on from the next available column each time it is run. to explain better - the numbers will keep changing, and different names will meet and unmeet certain criteria. the sub will keep running and update the met lists - copying over what was there previously - make sense?
 
Upvote 0
Does this work?
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:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
        
    End If
Next Tcell

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,396
Messages
6,124,685
Members
449,179
Latest member
kfhw720

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