Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Range, select, and printing arrays

I am just trying to learn VBA for Excel and was wondering if somebody might
help me. I am trying to understand how to select a cell (or range), how to
position the curser somewhere in that range (is that the same as
"collapsing"?), and how to print each value in an array.

I have created a small macro that factors all of the numbers in the first
row. Now I'd like to ask the user if they'd like to see all of the prime
numbers (see VBA code below). If so, I would like to display those in a
msgBox, preferably one per line. If the number that was factored was prime,
then "PRIME" is placed in row 5.

1) Do I need to decalre P(j) as an array to use it?
2) Is the Else: P(j) = "" required. I'm putting it in just to set initial
conditions just in case.
3) Is there a more efficient way of finding the value of the cell above the
active cell? I have done an ActiveCell.Offset to select it, but can I find
the value without first selecting the cell and making it active?
4) Can somebody explain the .Range("A1") when I am doing an offset. It
seems that no matter what the active cell is, "A1" is filled in.
5) How do I print all the values in an array? Do I need a For Each loop, or
does VBA have an easier way?

'Display the prime numbers if the user would like
Response = MsgBox(prompt:="Do you want to see the prime numbers?",
Style:=vbYesNo)
If Response = vbYes Then
Range("A5").Select
For j = 1 To 255
If ActiveCell.Value = "Prime" Then
ActiveCell.Offset(1, 0).Range("A1").Select
P(j) = ActiveCell.Value
Else: P(j) = ""
End If

For Each j In P(j)
' make a textbox that prints all the prime numbers, 1 per line


Thanks in advance!!
--
Jeff Ciaccio
Physics and AP Physics Teacher
Sprayberry High School; Marietta, GA
Blog: http://sprayberry.typepad.com/ciaccio

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate / Select Subset of Arrays Andrew Hall NZ Excel Programming 2 March 17th 07 01:51 PM
Using Arrays to Fill a Range nenad Excel Programming 6 February 24th 07 07:24 PM
Using arrays or range in IF function - HELP PLS MickJJ Excel Worksheet Functions 1 February 10th 06 05:43 PM
Using arrays to select a series of cells [email protected] Excel Discussion (Misc queries) 1 December 27th 05 10:47 PM
Using Arrays to select Shapes Don Rouse Excel Programming 1 July 18th 04 07:27 AM


All times are GMT +1. The time now is 10:29 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"