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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • 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.Ce lls(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.mu ltiCells((2,5), (2,37)).Value = 55

    ?

    Tony

  • =?Utf-8?B?R2FyeScncyBTdHVkZW50?=

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

    No iteration is needed:

    Sub tony()
    Set objWorksheet = ActiveSheet
    objWorksheet.Ra nge(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:
    As well known I can write into an Excel cell a certain value with in a VBS script with e.g.
    >
    objWorksheet.Ce lls(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.mu ltiCells((2,5), (2,37)).Value = 55
    >
    ?
    >
    Tony
    >
    >

    Comment

    • Dave Peterson

      #3
      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.Ra nge("E2").resiz e(1,33).Value = 55


      Gary''s Student wrote:
      >
      No iteration is needed:
      >
      Sub tony()
      Set objWorksheet = ActiveSheet
      objWorksheet.Ra nge(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:
      >
      As well known I can write into an Excel cell a certain value with in a VBS script with e.g.

      objWorksheet.Ce lls(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.mu ltiCells((2,5), (2,37)).Value = 55

      ?

      Tony
      --

      Dave Peterson

      Comment

      • Cor Ligthert[MVP]

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

        Same fun

        Cor

        "Tony Bansten" <tonytony@hotma il.comschreef in bericht
        news:485c2918$0 $27444$9b4e6d93 @newsspool4.arc or-online.net...
        As well known I can write into an Excel cell a certain value with in a VBS
        script with e.g.
        >
        objWorksheet.Ce lls(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.mu ltiCells((2,5), (2,37)).Value = 55
        >
        ?
        >
        Tony
        >

        Comment

        Working...