Excel vba: type range and cell

I am a bit confused by the cell and range in vba (excel). Logically, I could think of a cell as a range with size = 1; and I think it’s easy to make a range from a cell.

If I read the api of the EntireRow property here it works at range. But the following code work indicating that "cell'variable inside a loop is a range

Set import = Sheets("import") Set spRange = import.Range("A2") Set spRange = import.Range("A2:" & spRange.End(xlDown).Address) For Each cell In spRange dict.Add cell.Offset(0, 2).Text, cell.EntireRow Next cell 

At the same time, the code below returns an error indicating a type mismatch when the delete function is called. What should be the type of targetCell in the function definition?

 Set spRange = mySheet.Range("b2", mySheet.Range("b2").End(xlDown)) For Each cell In spRange val = removecell (cell) Next cell Public Function removecell(targCell As Range) As Boolean removecell = False End Function 
+6
source share
1 answer

This compiles and runs:

 Sub Tester() Dim spRange As Excel.Range Dim cell As Excel.Range Dim mySheet As Excel.Worksheet Dim val As Boolean Set mySheet = ActiveSheet Set spRange = mySheet.Range("b2", mySheet.Range("b2").End(xlDown)) For Each cell In spRange val = removecell(cell) Next cell End Sub Public Function removecell(targCell As Range) As Boolean removecell = False End Function 
+4
source

Source: https://habr.com/ru/post/909401/


All Articles