Multiple ranges in Excel with Vb.net

Asked

Viewed 18 times

0

I am trying to set a range in Vb.net to write data in the blue marked fields:

I tried to use this code I found on the Microsoft help pages but I think it is intended for VBA only:

Sub ClearRanges() 
   Worksheets("Sheet1").Range("C5:D9,G9:H16,B14:D18").ClearContents 
End Sub

My current code is this:

Dim appXL As Excel.Application
Dim wbXL As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim raXL As Excel.Range

Try
   ' Open workbook.
   wbXL = appXL.Workbooks.Open(My.Application.Info.DirectoryPath & "\test.xltx")
   shXL = wbXL.ActiveSheet

   ' Define Range.
   shXL.Range("A2:E2,A5:E5,A8:E8,A11:E11,A14:E14,A17:E17,A20:E20,A23:E23,A26:E26,A29:E29,A32:E32,A35:E35,A38:E38").Value = "TEST"
Catch ex As Exception
   MessageBox.Show("Error : " + ex.Message)
   appXL.Quit()
End Try
  • 1

    Please translate your question.

  • I’m sorry, I already have this.

  • The content is not written in the spreadsheet?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.