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!

Excel 2010 VBA how can I delete the values in a column by using the column heading

Status
Not open for further replies.

DougP

MIS
Dec 13, 1999
5,985
US
Is there a way to refer the a column by its name in the top cell. this is also set up as a filter.
the column name is Totals and it is column "C" the heading Totals is in C1 so I don't want to delete that.
I have this code but can it refer to "totals" some how, as it might not be column "C".
Code:
    With ActiveWorkbook.Worksheets("Sheet2")
        .Range("C2", .Range("C2").End(xlDown)).Delete
    End With

DougP
 
What about this ?
Code:
With ActiveWorkbook.Worksheets("Sheet2")
  For c = 1 To .Cells.Columns.Count
    If .Cells(1, c) = "Totals" Then
      .Range(.Cells(2, c), .Cells(2, c).End(xlDown)).Delete
    End If
End With

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
hi,

If you were using the Structured table feature,
Code:
[Table1[Total]].ClearContents

If you use Named Ranges based on the values in the TOP ROW,
Code:
[Total].ClearContents
or
Code:
Range("Total").ClearContents




Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
this might also work for you
Code:
    With ActiveSheet.UsedRange
        Intersect(Rows(1).Find("Total").EntireColumn, Range(Cells(2, 1), Cells(.Rows.Count, 1)).EntireRow).ClearContents
    End With


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