Rabu, 05 Februari 2014

Re: [MS_AccessPros] Copying chunks of data to a new location with macro

 

Jerry-


Well, we're not necessarily Excel experts here, but I would write a loop with a variable to save the "last" name you moved.  When you hit a "blank" name, you're done.  Something like this:

Dim strLastName As String, intStartRow As Integer, intFirstNewLoc As Integer

    intStartRow = 1
    intFirstNewLoc = 1000
    Do Until TeacherName(intStartRow) = ""
        ' If new name, then skip 1
        If TeacherName(intStartRow) <> strLastName Then intFirstNewLoc = intFirstNewLoc + 1
        NewName(intFirstNewLoc) = TeacherName(intStartRow)
        intStartRow = intStartRow + 1
        intFirstNewLoc = intFirstNewLoc + 1
    Loop

Just pseudo code, but maybe you get the idea.

John Viescas, Author
Microsoft Access 2010 Inside Out
Microsoft Access 2007 Inside Out
Microsoft Access 2003 Inside Out
Building Microsoft Access Applications 
SQL Queries for Mere Mortals 
(Paris, France)




On Feb 5, 2014, at 4:22 PM, Jerry Mathers <jerrymathersasthebeav@yahoo.com> wrote:

I have a situation where information is being sorted by the items in Column A.  The info in that column is repeating since it represents classroom teachers.  The rest of the row represents data about each of their students--one row per student.  So the teacher name in Column A repeats for each student's info.  At the end of that class the teacher name changes and this happens again for the next teacher until there are no more classes.

I need to copy all the rows for an individual teacher to a new location in the Worksheet.  Each teacher and the corresponding student data is copied to its own location so that the information in Column A is separated out.  The original data in Column A needs to stay where it is. The number of teachers represented in Column A isn't always going to be the same because different grades have more or fewer classes/teachers.  It would be nice, and easy if this wasn't the case.  But, I'm not sure how to go about this.

One thought I had was to insert a blank row between the end of one teacher and the beginning of the next teacher.  Then I'd know what chunk of data to grab and move. I know how to insert the blank row, but my problem is I don't know how to grab each chunk and move it and also determine when I'm out of classes so I can stop trying to move data.

Is there a better way to go about this?  Any help would be greatly appreciated.


__._,_.___
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (2)
.

__,_._,___

Tidak ada komentar:

Posting Komentar