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 6584483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:32:33+00:00 2026-05-25T16:32:33+00:00

Okay Now I have got another problem with variants while working on it. I

  • 0

Okay Now I have got another problem with variants while working on it. I have succefully copied one variant to other. Now how do I determine the size of the new variant

Var1 = Sheet7.Range("B2:E2721").Value  ' 1st variant
ReDim Var2(1 To UBound(Var, 1), 1 To UBound(Var, 2)) ' New variant

Ok after doing some calculations out of 2720 rows, I have copied 2020 rows into new variant and the other values from 2020 to 2720 are empty in the new variant . Now I have to know the size of new variant. I have tried these

ubound(var2,1) ' its giving the size as 2721 not as 2020

How can we find out the size of variant to the used range ignoring the empty one. because the size plays crucial part when we perform operations during loop or creating a another variant based on the other variant. and cant we define a variant without mentioning its dimensions? I Need to do split operation and add them to a variant, If that is the case I dont know how many split operations are performed and how many variables are taken out sometimes 20 or 40 , this should be copied to variant so we need a variant which is dynamic or something that can be resized

  • 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-25T16:32:34+00:00Added an answer on May 25, 2026 at 4:32 pm

    As per jonsca’s comment if you know how many records have been written or manipulated (2020) then you can cut the array from the 2721 record size at the end

    The trick here is that you can’t redim the first dimension of an array and preserve the existing data so we need a three stage workaround

    1. Create the second array with a horizontal size equal to the vertical size of array 1, and a vertical size equal to the horizonatl size of array 1 (so rather than 2720 rows by 4 columns we use 4 rows by 2720 columns)
    2. Cut the columns from 2720 to 2020 at code end and preserve the written records
    3. Dump the second array back to Excel but use Transpose to turn the 4 rows by 2020 columns into 2020 rows * 4 columns

    Sample below (dumps to B2:E2021 on your second sheet)

    Sub VarExample2()
    Dim Var1()
    Dim Var2()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Set ws1 = ActiveWorkbook.Sheets(1)
    Set ws2 = ActiveWorkbook.Sheets(2)
    Dim lngrow As Long
    Var1 = ws1.Range("B2:E2721").Value2
    'make our second array with columns equal to rows in the first, rows equal to columns
    ReDim Var2(1 To UBound(Var1, 2), 1 To UBound(Var1, 1))
    'Put some data in the second array, but not all 2720 records
    For lngrow = 1 To 2020
    Var2(1, lngrow) = lngrow & " apple up on top"
    Var2(2, lngrow) = lngrow & " apple up on top next to the other one"
    Next lngrow
    'Cut the second array from 2720 columns to 2020
    ReDim Preserve Var2(1 To UBound(Var1, 2), 1 To lngrow)
    'Rotate the data from columns/rows into rows/columns in Excel
    ws2.[b2].Resize(lngrow, UBound(Var2, 1)) = Application.Transpose(Var2)
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay. Now I give up. I have been playing with this for hours. I
first, I can't stand Crystal! Okay, that's off my chest... Now, we have an
Okay, Ive got a cog (toothed gear) that I have drawn in opengl. I
Okay, here is my problem: I have a form that requires to have two
Okay, got a question. I have assembled a bit mask for options. Basically my
Okay, now I've got this thing I need to do with Javascript but I
correction it works now thanks everyone. Okay so now I have updated my main
Okay, so I'm making a table right now for Box Items. Now, a Box
Okay, Here is what I'm trying to do... Right now it is compiling but
Okay, so I'm running a small test webserver on my private network. I've got

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.