I want to get the number of rows and columns in my "selection" range, but for some reason Columns.Count returns 1 when I have multiple columns selected.
Anyone knows why?
I am using excel 2013 32 bit.
Anyone knows why?
I am using excel 2013 32 bit.
Code:
[COLOR=#333333]Sub test()[/COLOR]
[COLOR=#333333]Dim sourceSht As Worksheet[/COLOR]
[COLOR=#333333]Dim targetSht As Worksheet[/COLOR]
[COLOR=#333333]Dim Table As ListObject[/COLOR]
[COLOR=#333333]Dim LastRow As Long[/COLOR]
[COLOR=#333333]Dim selection As Range[/COLOR]
[COLOR=#333333]Set sourceSht = ActiveWorkbook.Sheets("Colaboradores")[/COLOR]
[COLOR=#333333]LastRow = sourceSht.ListObjects("Table3").Range.Columns("BB").Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row[/COLOR]
[COLOR=#333333]Set targetSht = ActiveWorkbook.Sheets("Sheet3")[/COLOR]
[COLOR=#333333]'Check for existance of table[/COLOR]
[COLOR=#333333]'SELECT ALL NEEDED DATA[/COLOR]
[COLOR=#333333]Set selection = sourceSht.Range("Table3[UE i" & vbLf & "(área)], Table3[UE ii" & vbLf & "(unidade)],Table3[2013 -1ºSemestre]:Table3[2019-2ºSemestre]").Offset(-1, 0)[/COLOR]
[COLOR=#333333]Debug.Print selection.Columns.Count <<<<<<<< Here the console returns 1 ( also the number of rows does not change with or without the offset, which is weird to me too)[/COLOR]
[COLOR=#333333]'COPY AND PASTE INTO NEW SHEET[/COLOR]
[COLOR=#333333]selection.Copy[/COLOR]
[COLOR=#333333]targetSht.Range("A1").PasteSpecial xlPasteValues[/COLOR]
[COLOR=#333333]'CREATE NEW TABLE[/COLOR]
[COLOR=#333333]Debug.Print h[/COLOR]
[COLOR=#333333]Set selection = targetSht.Range("A1").Resize(w, h)[/COLOR]
[COLOR=#333333]w = selection.Rows.Count[/COLOR]
[COLOR=#333333]h = selection.Columns.Count[/COLOR]
[COLOR=#333333]Debug.Print h[/COLOR]
[COLOR=#333333]targetSht.ListObjects.Add(xlSrcRange, selection, , xlYes).Name = "MyTable"[/COLOR]
[COLOR=#333333]End Sub[/COLOR]