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

T

Tony Bansten

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
 
P

Per Jessen

As well known I can write into an Excel cell a certain value with in a VBSscript 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

Hi Tony

Look at this:

objWorksheet.Range("B5:B37").Value = 55
objWorksheet.Range(Cells(2, 5), Cells(2, 37)).Value = 55

Regards,
Per
 
L

Lars-Åke Aspelin

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


Try this:

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

Hope this helps. / Lars-Åke
 
G

Gary''s Student

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.
 
D

Dave Peterson

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
 
D

Dave Peterson

Check your other post and make sure you qualify all those range objects
(.range() and .cells()).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top