Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default Populate array

Hi Beto,

You could do something like this:

Sub test()
Dim Names As Variant

Names = Array("N1", "N2", "N3")

Sheets("Sheet1").Range("A1:C1").Value = Names
End Sub

BTW, you should probably use a different variable name than Names, as Names
is the name of a collection of Name objects. In this case, you may want to
use vNames or avNames (v for Variant or av for "array of Variants").

--
Regards,

Jake Marx
MS MVP - Excel
www.longhead.com

[please keep replies in the newsgroup - email address unmonitored]


Beto wrote:
Hi,
Can I populate an array in a similar way than this?

Dim Names(1 to 3) as String
Names=Array("N1","N2","N3")

I like something like that instead of:
Names(1)="N1": Names(2)="N2": Names(3)="N3"

BTW, which one would bethe best way to fill column headings that
aren't in any Workbook, just from VBA?

Regards,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate array

Hi,
Can I populate an array in a similar way than this?

Dim Names(1 to 3) as String
Names=Array("N1","N2","N3")

I like something like that instead of:
Names(1)="N1": Names(2)="N2": Names(3)="N3"

BTW, which one would bethe best way to fill column headings that aren't
in any Workbook, just from VBA?

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate array

Jake Marx wrote:

Hi Beto,

You could do something like this:

Sub test()
Dim Names As Variant

Names = Array("N1", "N2", "N3")

Sheets("Sheet1").Range("A1:C1").Value = Names
End Sub


Worked beatifully... Is there a way to assign comlumn widths in a
similar way?

As you may find out I'm formatting a sheet for a report. I thought of
using a template sheet, but I'm doing this because is harder and helps
me to learn more VBA.

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate array

Beto,

Is this what you want

Option Base 1

Sub ColumnWidths()

Dim aryWidths
Dim i As Long

aryWidths = Array(10, 15, 22, 34)

For i = LBound(aryWidths) To UBound(aryWidths)
Columns(i).ColumnWidth = aryWidths(i)
Next i

End Sub


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Beto" wrote in message
...
Jake Marx wrote:

Hi Beto,

You could do something like this:

Sub test()
Dim Names As Variant

Names = Array("N1", "N2", "N3")

Sheets("Sheet1").Range("A1:C1").Value = Names
End Sub


Worked beatifully... Is there a way to assign comlumn widths in a
similar way?

As you may find out I'm formatting a sheet for a report. I thought of
using a template sheet, but I'm doing this because is harder and helps
me to learn more VBA.

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Populate array

Beto,

That works, but I added the bits about lower and upper array bounds as you
said you wanted to learn more VBA <G.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Beto" wrote in message
...
Beto wrote:

Jake Marx wrote:

Hi Beto,

You could do something like this:

Sub test()
Dim Names As Variant

Names = Array("N1", "N2", "N3")

Sheets("Sheet1").Range("A1:C1").Value = Names
End Sub


Worked beatifully... Is there a way to assign comlumn widths in a
similar way?


Nevermind, after a lot of trial & error I came up with this:

Dim vColumnWidths as Variant

vColumnWidths = Array(10, 20, 30)
Range("A1:C1").ColumnWidth = vColumnWidths

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate array

Beto wrote:

Jake Marx wrote:

Hi Beto,

You could do something like this:

Sub test()
Dim Names As Variant

Names = Array("N1", "N2", "N3")

Sheets("Sheet1").Range("A1:C1").Value = Names
End Sub


Worked beatifully... Is there a way to assign comlumn widths in a
similar way?


Nevermind, after a lot of trial & error I came up with this:

Dim vColumnWidths as Variant

vColumnWidths = Array(10, 20, 30)
Range("A1:C1").ColumnWidth = vColumnWidths

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 140
Default Populate array

Bob Phillips wrote:

Beto,

That works, but I added the bits about lower and upper array bounds as you
said you wanted to learn more VBA <G.


Thanks, Is always better to know more ways to do the same things.

Regards,
--
Beto
Reply: Erase between the dot (inclusive) and the @.
Responder: Borra la frase obvia y el punto previo.

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
Prevent cell/array references from changing when altering/moving thecell/array nme Excel Discussion (Misc queries) 1 September 19th 08 01:53 PM
Array to Populate ListBox Problem pallaver Excel Discussion (Misc queries) 1 July 25th 08 08:50 AM
Populate an array that is a subset of a larger array? Jeff Excel Worksheet Functions 1 September 25th 07 12:51 AM
meaning of : IF(Switch; Average(array A, array B); array A) DXAT Excel Worksheet Functions 1 October 24th 06 06:11 PM
variant array containing cel adresses convert to actual ranges-array Peter[_21_] Excel Programming 5 December 10th 03 09:50 PM


All times are GMT +1. The time now is 11:49 PM.

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"