INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

VBA Visual Basic for Applications (Microsoft) FAQ

Excel How To

How can i quickly reduce my test data by Chance1234
Posted: 23 Mar 06

These are two routines i regularly use to reduce my test data .


The first routine hides the middle group of data and the second one randomly removes lines of data, down to a specified size

CODE

Public Sub RemoveMiddleData()
'function to remove the middle data of the graph
Dim intXFirstRow, intXLastRow As Integer
Dim IntCntofRows As Integer
Dim rwIndex As Integer
Dim intCeiling As Integer
Dim strStrip
Dim lrows As Long


intCeiling = 100 'maximum number of rows change to whatever you like

lrows = Sheet1.Rows.Count

For I = 1 To lrows - 1

If Trim(Sheet1.Cells(I + 1, 1).Value) = "" Then Exit For
    
Next I

lrows = I

 If lrows > intCeiling Then
    intXFirstRow = Round(lrows / 3, 0)
    intXLastRow = lrows - (intXFirstRow)
        While intXFirstRow + (intXran - intXLastRow) > intCeiling
            intXFirstRow = intXFirstRow - 1
            intXLastRow = intXLastRow + 1
        Wend
    IntCntofRows = intXFirstRow
    strStrip = intXFirstRow & ":" & intXLastRow
    Sheet1.Range(strStrip).EntireRow.Hidden = True ' hide or delete rows
End If
    
End Sub

Public Sub RandomlyRemoveData()
Dim lrows
Dim intStart
Dim intTarget

intTarget = 60 ' number of rows you want to reduce your data down to

lrows = Sheet1.Rows.Count

For I = 1 To lrows - 1
    If Trim(Sheet1.Cells(I + 1, 1).Value) = "" Then Exit For
Next I

lrows = I

intStart = 1
While lrows > intTarget
    Randomize
    If Int((3 * Rnd) + 1) = 1 Then
        Sheet1.Rows(intStart).Delete
        lrows = lrows - 1
    End If
    intStart = Round(((lrows * Rnd) + 1))
Wend
          
End Sub

Back to VBA Visual Basic for Applications (Microsoft) FAQ Index
Back to VBA Visual Basic for Applications (Microsoft) Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close