Consulting

Results 1 to 6 of 6

Thread: Solved: VBA to delete all "unused" formulas

  1. #1
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location

    Solved: VBA to delete all "unused" formulas

    Does anyone have any code that can delete all formulas that are not using used.

    I have a sheet called "Input" that gets populated via an Import of a .csv file.

    On a sheet called "Data" I have references to the "Input" sheet via the following formula:

    =IF('Input'!$A$1="","",'Input'!$A$1)

    This formula is replicated down to row 300 (Cell A300) on the Data sheet.

    On the "Input" sheet there is only 30 entries - this time, it can vary up to 300 entries.

    How can I delete the "unsed" formulas that are in A31:A300 on the "Data" sheet?

    This might not be the best way but eventually I'm trying to have the Charts that reference the "Data" sheet automaticlly adjust the Source Rows to match the number of entries on the Input (or Data) sheet.

    Thanks for any and all help...(God knows I need it)

    Jim

  2. #2
    VBAX Tutor nst1107's Avatar
    Joined
    Nov 2008
    Location
    Monticello
    Posts
    245
    Location
    [vba]Dim c As Range
    For Each c In Sheets("Data").Range("A31:A300")
    If c.Formula <> "" And c.Value = "" Then c.Delete (xlShiftUp)
    Next[/vba]

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    When deleting rows, work from the bottom up.
    [VBA]Sub DelRows()
    Dim c As Range, i As Long
    For i = 300 To 31 Step -1
    Set c = Cells(i, "A")
    If c.HasFormula And c.Value = "" Then c.EntireRow.Delete (xlShiftUp)
    Next i
    End Sub[/VBA]

  4. #4
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location
    Can the range be:

    .Range("A1:A300") so that if there are less then 30 entries it will delete all the "unused" formulas?

    Any idea how to get a Chart to automatically adjust based on the number of rows in the source table?

  5. #5
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    I guess you could delete the 3 from 31 to make it go to row 1. This will get the last row.
    [VBA]Sub DelRows()
    Dim c As Range, i As Long
    For i = Range("A" & Rows.Count).End(xlUp).Row To 1 Step -1
    Set c = Cells(i, "A")
    If c.HasFormula And c.Value = "" Then c.EntireRow.Delete (xlShiftUp)
    Next i
    End Sub[/VBA]

    Your last question is off topic. It is best to start a new thread for such. You can use Dynamic Named ranges or use the Change event to reset the SeriesCollection. I prefer the first. See http://peltiertech.com/Excel/Charts/Dynamics.html

  6. #6
    VBAX Mentor
    Joined
    Jan 2009
    Posts
    304
    Location
    Thank you very much...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •