1

I'd like to ask you this question: I have in column B of my Excel worksheet these cells

  • B1: Ciao / text
  • B2: stackoverflow / text
  • B3: =A1+A3 / formula (example)
  • B4: Fabio / text

I want to select only B1, B2, B4; in other words I want to select ONLY CELLS OF COLUMN B WHICH CONTAIN A TEXT, NOT A FORMULA

Is it possible do that in a code as:

rng = 'I DON'T KNOW'
For Each cella In rng
..
Bugs
  • 4,491
  • 9
  • 32
  • 41
Fabio Masino
  • 69
  • 2
  • 8

3 Answers3

2

Excel has this function built into SpecialCells, so you can do this:

Set rng = Sheets(2).Range("B1:B4").SpecialCells(xlCellTypeConstants)

Looping through worksheet ranges in Excel is very slow and best avoided

SWa
  • 4,343
  • 23
  • 40
1

you can use the .HasFormula command in a line written more or less as:

If Not cella.HasFormula Then

In this case you will need to copy/select (or whatever) the cell, otherwise not. Put this in your for loop and you're done!

Noldor130884
  • 974
  • 2
  • 16
  • 40
0
Columns("B:B").Select

Selection.SpecialCells(xlCellTypeConstants, 23).Select
Bugs
  • 4,491
  • 9
  • 32
  • 41
vigilent
  • 1
  • 1