Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using .xlUp but disregarding formulas in cells

Status
Not open for further replies.

davedave24

Programmer
Aug 26, 2010
113
GB
Hi. I have a problem using Selection.End(xlUp) - I need it to disregard cells with formulas in.

I've tried to substitute for a Do-While loop but it has the same effect (albeit with a different outcome)
Code:
    Do Until ActiveCell.Value = ""
       ActiveCell.Offset(-1, 0).Select
    Loop

 
hi,
Code:
Do Until ActiveCell.Value = ""
    if not ActiveCell.Offset(-1, 0).HasFormula then
       'this is NOT a formula
    end if
    Activecell.offset(1).select
Loop

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
I really don't like using Select and Activate, but sometimes it is required by the process.

Here's how I would code this, that puts each literal value in the range in the adjacent column for example...
Code:
    Dim r As Range
    
    For Each r In Range(Selection.End(xlUp), Selection)
        With r
            If Not .HasFormula Then
                .Offset(0, 1).Value = .Value
            End If
        End With
    Next

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top