Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:12+00:00 2026-05-24T12:43:12+00:00

I have an array of X elements, and let’s say X = 50. How

  • 0

I have an array of X elements, and let’s say X = 50.

How do I remove every 5th element of the array?

Thus, the end result should be an array of only 40 elements left, since every 5th element was taken out….

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:43:13+00:00Added an answer on May 24, 2026 at 12:43 pm

    The code below isn’t tested but it should be pretty close, after the code has run all non divisible by 5 elements will be contained in array ‘strSecond’.

    UPDATE

    Code below has now been tested –

    Dim strFirst(49) As String
    Dim strSecond() As String
    Dim ArrCount As Integer
    
    ArrCount = 0
    
    For i = 1 To 50
        strFirst(i - 1) = i
    Next
    
    For i = 0 To 49
     If (i + 1) Mod 5 <> 0 Then
        ReDim Preserve strSecond(ArrCount)
        strSecond(ArrCount) = strFirst(i)
        ArrCount = ArrCount + 1
      End If
    Next
    
    For i = 0 To UBound(strSecond)
        Debug.Print strSecond(i)
    Next
    

    UPDATE II

    This would work for a multi-dimensional array (only the upper bound of the last dimension in a multidimensional array can be changed when you use the Preserve keyword) –

    Dim strFirst(1, 49) As String
    Dim strSecond() As String
    Dim ArrCount As Integer
    
    ArrCount = 0
    
    For i = 1 To 50
        strFirst(0, i - 1) = i
        strFirst(1, i - 1) = i
    Next
    
    For i = 0 To 49
     If (i + 1) Mod 5 <> 0 Then
        ReDim Preserve strSecond(1, ArrCount)
        'If you have more than two dimensions could write a loop to do this
        'For j = 0 To UBound(strFirst,1) etc
        strSecond(0, ArrCount) = strFirst(0, i)
        strSecond(1, ArrCount) = strFirst(1, i)
        ArrCount = ArrCount + 1
      End If
    Next
    
    For i = 0 To UBound(strSecond, 2)
        Debug.Print strSecond(0, i) + "-" + strSecond(1, i)
    Next
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have an array, @theArr, which holds 1,000 or so elements such
I have an array with let's say, 500 elements. I know I can select
Let's say I have an array of elements for which a total ordering exists.
Let's say that we have an array with n elements (n > 0). We
How can I remove certain items of an array? Let's say I have an
Let's say I have an array of n elements(numbers or words), I want to
Let's say I have a vector (array, list, whatever...) V of N elements, let's
I have an array Items which has 10 elements. I need to remove the
Let's say, I want to separate certain combinations of elements from an array. For
Let's say I have an array k = [1 2 0 0 5 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.