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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:49:07+00:00 2026-05-28T15:49:07+00:00

I have data stored in some column (Say, Column A). The length of Column

  • 0

I have data stored in some column (Say, Column A). The length of Column A is not fixed (depends on previous steps in the code).

I need a histogram for the values in Column A, and have it in the same sheet. I need to take the values in column A, and automatically compute M Bins, then give the plot.

I looked online for a “simple” code, but all codes are really fancy, with tons of details that I don’t need, to the extent that I am not even able to use it. (I am a VBA beginner.)

I found the following code that seems to do the job, but I am having trouble even calling the function. Besides, it only does computations but does not make the plot.

Sub Hist(M As Long, arr() As Single)
Dim i As Long, j As Long
Dim Length As Single
ReDim breaks(M) As Single
ReDim freq(M) As Single

For i = 1 To M
    freq(i) = 0
Next i

Length = (arr(UBound(arr)) - arr(1)) / M

For i = 1 To M
    breaks(i) = arr(1) + Length * i
Next i

For i = 1 To UBound(arr)
    If (arr(i) <= breaks(1)) Then freq(1) = freq(1) + 1
    If (arr(i) >= breaks(M - 1)) Then freq(M) = freq(M) + 1
    For j = 2 To M - 1
        If (arr(i) > breaks(j - 1) And arr(i) <= breaks(j)) Then freq(j) = freq(j) + 1
    Next j
Next i

For i = 1 To M
    Cells(i, 1) = breaks(i)
    Cells(i, 2) = freq(i)
Next i
End Sub

And then I try to call it simply by:

Sub TestTrial()
Dim arr() As Variant
Dim M As Double
Dim N As Range

arr = Range("A1:A10").Value
M = 10

Hist(M, arr)    ' This does not work.  Gives me Error (= Expected)
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-28T15:49:08+00:00Added an answer on May 28, 2026 at 3:49 pm

    Not 100% sure as to the efficacy of that approach but;

    • Remove the parens as your calling a sub; Hist M, arr
    • M is declared as double but received by the function as a long; this won’t work so declare it in the calling routine as long
    • You will need to recieve arr() As Variant
    • Range -> Array produces a 2 dimensional array so the elements are arr(1, 1) .. arr(n, 1)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data that is stored in a TIMESTAMP(6) WITH TIMEZONE column in
Say i have a stored proc that inserts some data into a table. If
I have some prices in my DB which are stored as data type money
I have a stored procedure that logs some data, how can I call this
I have a stored proc which unions some data and returns back. At max
I've got some financial data to store and manipulate. Let's say I have 2
I have some user-specific data that I need to store in SharePoint and make
In SQL Server, I have a table where a column A stores some data.
I have some varbinary data stored in a table in MS Sql Server 2005.
I have a generated nested Array which I store some data. How can i

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.