Note that there are some explanatory texts on larger screens.

plurals
  1. POVB.NET excel deleting multiple columns at the same time
    primarykey
    data
    text
    <p>I am trying to delete more than one column in my excel sheet.</p> <pre><code> For Each lvi In ListView1.Items If lvi.Checked = True Then arrayLetters = lvi.SubItems(1).Text &amp; ":" &amp; lvi.SubItems(1).Text &amp; "," &amp; arrayLetters End If Next arrayLetters = arrayLetters.Substring(0, arrayLetters.Length - 1) Dim rg As Excel.Range = xlSheet.Columns(arrayLetters) rg.Select() rg.Delete() </code></pre> <p>The value of <strong>arrayLetters</strong> is <strong>"G:G,F:F"</strong>. For some reason that doesn't seem to work once it gets there to delete them! Only reason i am doing it this way is so that it doesn't update the table and loop to the other one. In other words, if i delete each one individually then the column moves and the letter will not be the same the next go around.</p> <p>The error is on the <strong>Dim rg As Excel.Range = xlSheet.Columns(arrayLetters)</strong> line and it says:</p> <p><strong>Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))</strong></p> <p>Any help would be great!</p> <p>David</p> <p><strong>SOLVED</strong></p> <pre><code> For Each lvi In ListView1.Items If lvi.Checked = False Then arrayLetters = lvi.SubItems(2).Text &amp; "," &amp; arrayLetters 'Puts numbers in BACKWORDS End If Next arrayLetters = arrayLetters.Substring(0, arrayLetters.Length - 1) Dim theNumbers As String() = arrayLetters.Split(",") Dim num As Integer = 0 xlApp.ScreenUpdating = False For Each num In theNumbers xlSheet.Columns(num).delete() 'Deletes columns in reverse order (7,5,4...) Next </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload