Welcome to Dream.In.Code
Become a VB Expert!

Join 149,485 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,338 people online right now. Registration is fast and FREE... Join Now!




Sorting re-occuring data into a single row

 
Reply to this topicStart new topic

Sorting re-occuring data into a single row

keirw
3 May, 2007 - 11:38 AM
Post #1

New D.I.C Head
*

Joined: 3 May, 2007
Posts: 4


My Contributions
I need some help in sorting the data I have gathered from the code below.




The data is collating information with regards an activity which can be executed by up to four people. Each individual has a unique identifier.
I now want to report back on every individuals performance but cannot get the required data into a single row for each individual.



This post has been edited by keirw: 3 May, 2007 - 11:49 AM
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 11:43 AM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Nice code... what would you like us to do with it? Also, next time try putting your code in [code] tags like the big message says to do wink2.gif
User is online!Profile CardPM
+Quote Post

keirw
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 12:01 PM
Post #3

New D.I.C Head
*

Joined: 3 May, 2007
Posts: 4


My Contributions
QUOTE(skyhawk133 @ 3 May, 2007 - 12:43 PM) *

Nice code... what would you like us to do with it? Also, next time try putting your code in [code] tags like the big message says to do wink2.gif


Sorry, I have not been doing this for long, only about two months off and on and I am no expert

User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 12:02 PM
Post #4

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Can you post the code that you removed please. We do need to see the code, we would just appreciate if put [code] tags around it so it displays properly in the forum here.
User is online!Profile CardPM
+Quote Post

keirw
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 12:42 PM
Post #5

New D.I.C Head
*

Joined: 3 May, 2007
Posts: 4


My Contributions

I hope this is right

CODE
Sub data()
Dim prnone As Integer
Dim prntwo As Integer
Dim prnthree As Integer
Dim prnfour As Integer
Dim storenumber As Variant
Dim jnynumber As Variant
Dim specialsa As Variant
Dim mytime

With Worksheets("Input")

    specialsa = .Cells(9, 2)
    prnone = .Cells(9, 4)
    prntwo = .Cells(10, 4)
    prnthree = .Cells(11, 4)
    prnfour = .Cells(12, 4)
    storenumber = .Cells(9, 6)
    jnynumber = .Cells(9, 8)
    mytime = TimeValue("01:00")
    
    Cells(9, 2).Value = "L"
    Cells(9, 4).Value = ""
    Cells(10, 4).Value = ""
    Cells(11, 4).Value = ""
    Cells(12, 4).Value = ""
    Cells(9, 6).Value = ""
    Cells(9, 8).Value = ""
    
    Cells(9, 2).Activate
    
End With

With Worksheets("data")

currentrow = 2
currentcolumn = 17

    If specialsa = "L" Then
    Do
    currentrow = currentrow + 1
    
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = specialsa
    End If
    
currentrow = 2
currentcolumn = 17

    If Not specialsa = "L" Then
    Do
    currentrow = currentrow + 1
    
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = specialsa
    End If
    
    
With Worksheets("data")

currentrow = 2
currentcolumn = 7

    If Not storenumber = 0 Then
    Do
    currentrow = currentrow + 1
    
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = storenumber
    End If
    End With
    
    
currentrow = 2
currentcolumn = 9



If Not jnynumber = 0 Then
    Do
    currentrow = currentrow + 1
  
  
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentcolumn = 1100
    If currentcoulmn = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = Time
    End If


currentrow = 2
currentcolumn = 2


If Not jnynumber = 0 Then
    Do
   currentrow = currentrow + 1
   currentcolumn = currentcolumn
  
  
   Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = jnynumber
    End If


If Not prnone = 0 Then
    Do
    currentrow = currentrow
    currentcolumn = currentcolumn + 1
  
  
   Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = prnone
    End If



If Not prntwo = 0 Then
    Do
    currentrow = currentrow
    currentcolumn = currentcolumn + 1
  
  
   Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = prntwo
    End If


If Not prnthree = 0 Then
    Do
    currentrow = currentrow
    currentcolumn = currentcolumn + 1
  
  
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = prnthree
    End If
    
    
    If Not prnfour = 0 Then
    Do
    currentrow = currentrow
    currentcolumn = currentcolumn + 1
  
  
   Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = prnfour
    End If
        
    
End With

ActiveWorkbook.Save

End Sub

Sub finishload()

Dim jnynumber As Variant
Dim nrps As Integer
Dim nbds As Integer
Dim prps As Integer
Dim pbds As Integer
Dim mytime

With Worksheets("Input")

jnynumber = .Cells(21, 3)
nrps = .Cells(21, 5)
nbds = .Cells(21, 6)
prps = .Cells(21, 7)
pbds = .Cells(21, 8)
mytime = TimeValue("01:00")

Cells(21, 3).Value = ""
Cells(21, 5).Value = ""
Cells(21, 6).Value = ""
Cells(21, 7).Value = ""
Cells(21, 8).Value = ""

Cells(21, 3).Activate


End With

Dim currentrow As Long

currentrow = 2

Dim currentcolumn As Long

currentcolumn = 2


With Worksheets("Data")
Do

currentrow = currentrow + 1

Loop Until .Cells(currentrow, currentcolumn) = "" Or .Cells(currentrow, currentcolumn) = jnynumber
    If .Cells(currentrow, currentcolumn) = "" Then
    MsgBox "Not Found"
    Exit Sub
    End If
.Cells(currentrow, 10) = nrps


End With


currentrow = 2
currentcolumn = 2

With Worksheets("Data")
Do

currentrow = currentrow + 1

Loop Until .Cells(currentrow, currentcolumn) = "" Or .Cells(currentrow, currentcolumn) = jnynumber
    If .Cells(currentrow, currentcolumn) = "" Then
    MsgBox "Not Found"
    Exit Sub
    End If
.Cells(currentrow, 11) = nbds
End With




currentrow = 2
currentcolumn = 2

With Worksheets("Data")
Do

currentrow = currentrow + 1

Loop Until .Cells(currentrow, currentcolumn) = "" Or .Cells(currentrow, currentcolumn) = jnynumber
    If .Cells(currentrow, currentcolumn) = "" Then
    MsgBox "Not Found"
    Exit Sub
    End If
.Cells(currentrow, 12) = prps
End With




currentrow = 2
currentcolumn = 2

With Worksheets("Data")
Do

currentrow = currentrow + 1

Loop Until .Cells(currentrow, currentcolumn) = "" Or .Cells(currentrow, currentcolumn) = jnynumber
    If .Cells(currentrow, currentcolumn) = "" Then
    MsgBox "Not Found"
    Exit Sub
    End If
.Cells(currentrow, 13) = pbds
End With


currentrow = 2
currentcolumn = 2

With Worksheets("Data")
Do

currentrow = currentrow + 1

Loop Until .Cells(currentrow, currentcolumn) = "" Or .Cells(currentrow, currentcolumn) = jnynumber
    If .Cells(currentrow, currentcolumn) = "" Then
    MsgBox "Not Found"
    Exit Sub
    End If
.Cells(currentrow, 14) = Time

End With

ActiveWorkbook.Save

End Sub

User is offlineProfile CardPM
+Quote Post

Jayman
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 01:04 PM
Post #6

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 7,302



Thanked: 66 times
Dream Kudos: 500
Expert In: Everything

My Contributions
Thank you for using [code] tags.

I understand you are new, however you still need to describe the problem you are experiencing. So that we know where to look to help you.

Post any error messages you are receiving or if you are not having a problem compiling, then describe what type of output problems you may be experiencing. Include the input you are using that is giving you the unexpected output.
User is offlineProfile CardPM
+Quote Post

tody4me
RE: Sorting Re-occuring Data Into A Single Row
3 May, 2007 - 01:22 PM
Post #7

Only Jenny Craig makes thin clients...
Group Icon

Joined: 12 Apr, 2006
Posts: 1,349



Thanked: 5 times
Dream Kudos: 100
My Contributions
very hard to read and follow what you are trying to accomplish.

First, declare ALL of your vars, not just the ones that you know about. add Option Explicit to check this for you.
Second, break down each section of code into functions. This particular part of code is just basically duplicated

QUOTE

CODE


currentrow = 2
currentcolumn = 17

    If specialsa = "L" Then
    Do
    currentrow = currentrow + 1
    
    Loop Until .Cells(currentrow, currentcolumn) = "" Or currentrow = 1100
    If currentrow = 1100 Then
    MsgBox "No Room"
    Exit Sub
    End If
    .Cells(currentrow, currentcolumn) = specialsa
    End If



You are duplicating the code and checking that the specialsa var is equal to L or not, and then doing basically the same thing if it is or not.

You can put most of this into one function, and just change the vars.

As for your asking for sort help, excel has a built in sort feature. just pull up the range that you want sorted (range(<cells1>, <cells2>).sort(column 1))

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 04:48PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month