+ Reply to Thread
Results 1 to 6 of 6

Basic Questions On How To Display Data

Hybrid View

  1. #1
    Registered User
    Join Date
    04-24-2009
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    19

    Basic Questions On How To Display Data

    Hi,

    I know this is basic, but I can't get it to work!!

    I am trying to insert numbers into the spreadsheet.

    Code:

    Sub TestPrint()
       Sheets("Sheet3").Select
       Range("A2").Select
       ActiveCell.Value = 5
        
    End Sub
    The books I have looked at show how to display numbers into a message box!

    Also, does the formatting matter in the VBA Editor? Does an extra leading space here or there make a difference?

    If I build an array in VBA, how do I display that on the worksheet? It will be 100 x 3 in size.

    Thanks

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Basic Questions On How To Display Data

    As you write code directly, go ahead and break the habit of selecting cells/ranges prior to manipulating them. It's unnecessary and slows down your code. I would write your code above in one line:
    Sheets("Sheet3").Range("A2").Value = 5
    Formatting doesn't matter, it's aesthetics. Properly indenting makes code easier to read, shows where new "sections of logic" start and stop. Ease of reading is so critical, this forum even requires posted code be in [ code ] tags for that very reason.

    As for building an array in VBA memory, I've never done that specific thing, but I can't imagine it's difficult writing the array into a range like above. Something like:

    Sheets("Sheet3").Range("A2:CV4").Value = MyArray
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    04-24-2009
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Basic Questions On How To Display Data

    JB,

    Thanks for your response. Regarding the array, is there a way I can specify a single cell and have the array start there? That way, I don't have to know the length of the array - it is n x 3? I would like to specify, say A10 as the starting point, and have the array fill in Col A,B and C.

    Insect

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Basic Questions On How To Display Data

    As indicated, I haven't used arrays in memory in that manner, but if it were my first time, I would try using it the same way I would have used a Range to see if it worked...researched from there...something like:

    MyArray.Copy Range("A1")
    I might have gotten lucky...

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Basic Questions On How To Display Data

    If I build an array in VBA, how do I display that on the worksheet? It will be 100 x 3 in size.
    Range("A1").Resize(100, 3).Value = MyArray
    Entia non sunt multiplicanda sine necessitate

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Basic Questions On How To Display Data

    Hehe, awesome, SHG, my guess floweth nowhere. Next thing for me to spend time getting to know...

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1