+ Reply to Thread
Results 1 to 6 of 6

Macro rto clear Data from where total value appears in Col A

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,767

    Macro rto clear Data from where total value appears in Col A

    I have data on Sheet "Data"


    I have tried to write code to clear data from where "Total value" appears to two rows below this and 6 columns to the right of where "Total value appears"


    I cannot get my code to clear this data


    It would be appreciated if someone could kindly assist me


     Sub Clear_lastValue()
    With Sheets(2)
    
       Dim c As Range
    
        Set c = .Columns(1).Find("Total Value", , , 1)
             
    .Cells(LR).Resize(2, 6).ClearContents
     
        End With
    End Sub

    I have attached sample data
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,643

    Re: Macro rto clear Data from where total value appears in Col A

    Sheets(2).Columns(1).Find("Total Value", , , 1).Resize(2, 6).ClearContents
    'Or
    'Sheets(2).Columns(1).Find("Total Value", , , 1).Range("a1:f2").ClearContents
    Last edited by jindon; 10-05-2020 at 11:17 PM.

  3. #3
    Registered User
    Join Date
    08-01-2020
    Location
    Viet nam
    MS-Off Ver
    2007, 2010
    Posts
    17

    Re: Macro rto clear Data from where total value appears in Col A

    You try:

    Sub Clear_Excelnewbie()
    Dim v As String, lr As Long
        With ThisWorkbook.Sheets("data")
            v = "Total Value"
            lr = .Range("A:A").Find(What:=v, LookIn:=xlValues).Row
            .Cells(lr, 1).Resize(2, 6).ClearContents
        End With
    End Sub

  4. #4
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,767

    Re: Macro rto clear Data from where total value appears in Col A

    Thanks for the help Guys, much appreciated


    Jindon what is the significance of ?
    ,,,1 in formula Find("Total Value", , , 1)

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,643

    Re: Macro rto clear Data from where total value appears in Col A

    Range.Find method parameters

    Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
    Constant 1 for xlWhole, 2 for xlPart.
    When names of the named arguments are omitted, you need to keep the order of parameters, so equivalent is
    Sheets(2).Columns(1).Find("Total Value", LookAt:=xlWhole)
    HTH

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,767

    Re: Macro rto clear Data from where total value appears in Col A

    Thanks for the explanation

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to Add together numbers in 2 cells (A10 & C19). Clear C19 and put total in A10
    By ILoveStMartin in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-04-2019, 07:22 AM
  2. [SOLVED] Macro to find Text Total in Row 1 and clear entire Col
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-29-2019, 12:05 AM
  3. [SOLVED] Macro to clear row containing Total and sum Col B and Col C
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-07-2019, 01:36 AM
  4. VBA to Clear contents from a range if text appears in a certain cell
    By sherman51 in forum Excel Programming / VBA / Macros
    Replies: 40
    Last Post: 01-20-2018, 04:07 PM
  5. Replies: 1
    Last Post: 06-21-2013, 04:05 AM
  6. Clear cell after message box appears
    By shivrklfc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-16-2012, 11:34 AM
  7. Add to Total and Clear Macro
    By abcd12 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-22-2008, 01:04 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1