×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Creating a simple array challenge!

Creating a simple array challenge!

Creating a simple array challenge!

(OP)
I am new to VB, and I have a question. I want to create an array from a range of cells, starting at C9 and using the xldown to go to the last nonblank cell to grab my array. Then, I would like to make the array be listed in two ways: if the number of cells is 1 (C9 only), it would only list C9. If it is more than 1, then the array would be resolved as "C9 + Chr(13) + Chr(10) + next cell" and loop through until the array is filled. Does anyone have any ideas on how this could properly be set up with a for/next statement? Will I need an If Then statement nested within the For/Next? Your input would be greatly appreciated.

RE: Creating a simple array challenge!

Why not just get the line number of the last row with a value, dimension the array and loop down to that line number?

http://virtualpipeline.spaces.msn.com

RE: Creating a simple array challenge!

It looks like you are trying to get a concatenated string rather than an array. You can only use a For/Next loop if you know the number of cells. In this case with VBA it's much easier to use a Do Loop, with the IsEmpty function as your test. Try this:

CODE

Private Sub CommandButton1_Click()
firstrow = 9
firstcol = 3
a = firstrow
Do
'mystring = mystring & vbCrLf & Cells(a, firstcol).Value
mystring = mystring & vbCrLf & Chr$(64 + firstcol) & CStr(a)
a = a + 1
Loop Until IsEmpty(Sheets(1).Cells(a, firstcol).Value)
Debug.Print mystring
End Sub
If you use the remmed out line instead of the following line you will get the values rather than the cell names

Good Luck
johnwm
________________________________________________________
To get the best from these forums read FAQ731-376: Eng-Tips.com Forum Policies before posting
Steam Engine enthusiasts
Steam Engine Prints

RE: Creating a simple array challenge!

(OP)
Every1, thanks 4 your input...it helps me to understand the how and why of visual basic. However, I was able to figure it out. Cheers!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources