+ Reply to Thread
Results 1 to 8 of 8

How to get variables in first open cell

  1. #1
    Registered User
    Join Date
    08-25-2016
    Location
    USA
    MS-Off Ver
    14.0.7172.5000 (32-bit)
    Posts
    96

    How to get variables in first open cell

    I'm trying to do is get three variables (name, score, grade) in columns A, B, and C respectively. I dimmed name as string, score as double, grade as string, and i as long. The first part takes input for name and score and determines grade based on numerical score.

    I think this code snippet caused Excel to crash. If so then why?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: How to get variables in first open cell

    Probably not crashing ... just gently looping through over 3 million cells

    Rows.Count is the number of rows in the worksheet and is over 1 million.

    You could do this ...

    Please Login or Register  to view this content.
    But it's still too many rows. You need to determine how many rows of data you have.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: How to get variables in first open cell

    Rows.Count is the number of rows in the sheet, i.e. 1,048,576! You do this three times!

    Something like this should get you closer to what you want, but without seeing the spreadsheet I'm really only guessing:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    08-25-2016
    Location
    USA
    MS-Off Ver
    14.0.7172.5000 (32-bit)
    Posts
    96

    Re: How to get variables in first open cell

    Dang... I thought there were fewer than 100K rows.

    My worksheet is empty. Why wouldn't it find and stop at the first open cell in each column (i.e. A1, A2, and A3)?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,464

    Re: How to get variables in first open cell

    Your testing the cell and doing/not doing something with it. You don't test for blank and exit.

  6. #6
    Registered User
    Join Date
    08-25-2016
    Location
    USA
    MS-Off Ver
    14.0.7172.5000 (32-bit)
    Posts
    96

    Re: How to get variables in first open cell

    Quote Originally Posted by TMS View Post
    Your testing the cell and doing/not doing something with it. You don't test for blank and exit.
    I believe you... I just don't understand where my attempt failed. Does this line not test for the blank and then _if blank_ go ahead and do something (specifically, assign a value to that cell)?

    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    11-26-2012
    Location
    Sydney
    MS-Off Ver
    2010
    Posts
    419

    Re: How to get variables in first open cell

    Ok, so your worksheet is empty...? What do you want it to look like after the macro is run?

    Try this:
    Please Login or Register  to view this content.
    Last edited by mgs73; 09-03-2019 at 06:42 PM.

  8. #8
    Registered User
    Join Date
    08-25-2016
    Location
    USA
    MS-Off Ver
    14.0.7172.5000 (32-bit)
    Posts
    96

    Re: How to get variables in first open cell

    Quote Originally Posted by mgs73 View Post
    Ok, so your worksheet is empty...? What do you want it to look like after the macro is run?

    Try this:
    Please Login or Register  to view this content.
    Nice. Can you explain the syntax and how it works?

    What I want is for the three cells to be populated once an open cell is found.

    I came up with this:

    Please Login or Register  to view this content.
    I kept it to the first 10 rows after you and TMS pointed out a million rows, etc. The problem with
    mine is the limitation, though, since the spreadsheet may have occupied cells there. I added the
    last MsgBox in that case (and it was instructive as it occurs when i = 11, not 10).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Open Server Drive for File Save with X2 Cell Variables
    By Trompie in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-15-2018, 07:19 PM
  2. [SOLVED] How to activate an open workbook that will have variables in its name
    By bwiddoes in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-27-2016, 05:11 PM
  3. [SOLVED] Open sheet macro with 2 variables
    By JO505 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2015, 04:20 PM
  4. Open different workbook and store data to variables
    By Cerkit in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 04-15-2013, 09:40 AM
  5. [SOLVED] Copying worksheet from another open workbook using variables, paste to active workbook
    By sanpedro_nz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-08-2012, 08:25 AM
  6. Open workbooks with variables in filename using loop
    By as1234 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-31-2011, 01:17 PM
  7. Declare Multiple Variables for any Open Workbooks
    By Bravurian17 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-14-2009, 11:11 PM

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