Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Is there a write-multi-cell-at-once function in VBS for Excel?

Reply
 
Old 06-20-2008   #1 (permalink)
Tony Bansten


 
 

Is there a write-multi-cell-at-once function in VBS for Excel?

As well known I can write into an Excel cell a certain value with in a VBS script with e.g.

objWorksheet.Cells(2, 5).Value = 55

Can I write the value 55 into multiple cells at once?
Imagine I want to write in all cells 2,5 .... 2,37 the value 55.
Do I really have to iterate through all cells individually or is there a function like

objWorksheet.multiCells((2,5),(2,37)).Value = 55

?

Tony


My System SpecsSystem Spec
Old 06-20-2008   #2 (permalink)
Gary''s Student


 
 

RE: Is there a write-multi-cell-at-once function in VBS for Excel?

No iteration is needed:

Sub tony()
Set objWorksheet = ActiveSheet
objWorksheet.Range(Cells(2, 5), Cells(2, 37)).Value = 55
End Sub

You only need a loop if you want individual values in individual cells, and
by using arrays properly, maybe not even then.
--
Gary''s Student - gsnu2007j


"Tony Bansten" wrote:
Quote:

> As well known I can write into an Excel cell a certain value with in a VBS script with e.g.
>
> objWorksheet.Cells(2, 5).Value = 55
>
> Can I write the value 55 into multiple cells at once?
> Imagine I want to write in all cells 2,5 .... 2,37 the value 55.
> Do I really have to iterate through all cells individually or is there a function like
>
> objWorksheet.multiCells((2,5),(2,37)).Value = 55
>
> ?
>
> Tony
>
>
My System SpecsSystem Spec
Old 06-20-2008   #3 (permalink)
Dave Peterson


 
 

Re: Is there a write-multi-cell-at-once function in VBS for Excel?

It's probably better to fully qualify those ranges in case objWorksheet isn't
the activesheet.

with objWorksheet
.Range(.Cells(2, 5), .Cells(2, 37)).Value = 55
end with

or

objWorksheet.Range("E2").resize(1,33).Value = 55


Gary''s Student wrote:
Quote:

>
> No iteration is needed:
>
> Sub tony()
> Set objWorksheet = ActiveSheet
> objWorksheet.Range(Cells(2, 5), Cells(2, 37)).Value = 55
> End Sub
>
> You only need a loop if you want individual values in individual cells, and
> by using arrays properly, maybe not even then.
> --
> Gary''s Student - gsnu2007j
>
> "Tony Bansten" wrote:
>
Quote:

> > As well known I can write into an Excel cell a certain value with in a VBS script with e.g.
> >
> > objWorksheet.Cells(2, 5).Value = 55
> >
> > Can I write the value 55 into multiple cells at once?
> > Imagine I want to write in all cells 2,5 .... 2,37 the value 55.
> > Do I really have to iterate through all cells individually or is there a function like
> >
> > objWorksheet.multiCells((2,5),(2,37)).Value = 55
> >
> > ?
> >
> > Tony
> >
> >
--

Dave Peterson
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
VistaPro + Excel 2007- cell copy very very slow Vista General
How to sedn data to an excel cell from another file using a vb script VB Script
VBscript Returns wrong value from Excel Cell VB Script
RE: Assign variable value to excel cell VB Script
Need sample for reading value from and writing value to cell E53 from outside Excel VB Script


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46