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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:17:48+00:00 2026-05-28T08:17:48+00:00

I want to be able to reorder a rectangular grid of data into a

  • 0

I want to be able to reorder a rectangular grid of data into a column. I have written some code and run some MsgBox’s to test some things and it seems to work right, except for the last line. That is, I have tested to make sure outputArray actually ends up with data in it and various other things. But, when I try to write the data in outputArray to the worksheet, it just enters all blanks (I had a previous version which didn’t automatically delete the original data, so I could see just the first column being blanked out). I assume it’s some easy mistake I can’t see. Can you help me figure out what’s wrong? (Excel 2010)

Sub PutDataIntoColumn()
' This sub assumes data comes in a rectangular grid
' And that data is read across row 1, then across row 2, and so on
' The data is reordered into a column of data and is output starting at the top left cell of the original rectangular grid
' The original grid of data is erased so only the column remains

    Dim inputRange As Range
    Dim inputArray() As Variant, outputArray() As Variant

    Set inputRange = Application.InputBox(Prompt:="Select Data", Title:="Data Into Column", Type:=8)
    inputArray = inputRange.Value

    ' Erase the data
    inputRange.Value = ""

    numRows = UBound(inputArray, 1)
    numCols = UBound(inputArray, 2)

    totalCells = numRows * numCols

    ReDim outputArray(totalCells, 1)

    firstCellRow = inputRange.Row
    firstCellCol = inputRange.Column

    For i = 1 To numRows
        For j = 1 To numCols
            outputArray((i - 1) * numCols + j, 1) = inputArray(i, j)
        Next j
    Next i

    ActiveSheet.Cells(firstCellRow, firstCellCol).Resize(totalCells).Value = outputArray

End Sub
  • 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-28T08:17:49+00:00Added an answer on May 28, 2026 at 8:17 am

    The easy mistake you are looking for is the lack of explicit lower bounds on your outputArray. Change the ReDim to

    ReDim outputArray(1 To totalCells, 1 To 1)
    

    Without this outputArray is declared 0 based, so is one row and column bigger than you expected

    FYI, an alternative to inputRange.Value = "" is inputRange.Clear

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want users to be able to filter grid data without using the intrinsic
I am creating a WPF data grid, and I want to be able to
I have a UITableView and I want to be able to reorder the rows
I want to be able to reorder the rows within a single grid. Im
Suppose I have some objects, and I want the user to be able to
I want to be able to make an HTTP call updating some select boxes
I want to be able to get an estimate of how much code &
I want a user to be able to reorder a list on a click
I have a JTable and I need to be able to reorder the columns.
I have some tabs on a page and I want to let a user

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.