Home » excel » excel – Select all cells in a column containing a text not a formula

excel – Select all cells in a column containing a text not a formula

Posted by: admin May 14, 2020 Leave a comment

Questions:

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
..
How to&Answers:

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

Answer:

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!

Answer:

Columns("B:B").Select

Selection.SpecialCells(xlCellTypeConstants, 23).Select