+ Reply to Thread
Results 1 to 19 of 19

I need to create a reset button that will reset rows containing a specific value

Hybrid View

  1. #1
    Registered User
    Join Date
    04-02-2016
    Location
    Stavanger, Norway
    MS-Off Ver
    MS Office 2013
    Posts
    19

    Re: I need to create a reset button that will reset rows containing a specific value

    I really need help with this guys... let me explain in a better way...

    This code does exactly what I want:

    Private Sub CommandButton1_Click()
    
    If Range("F21").Value = "Hospedado" Then
    Range("F21", "X21").Value = ""
    End If
    
    End Sub
    
    That's only for the first row F. I have another 150 rows that need the same coding. So this works as well:

    Private Sub CommandButton1_Click()
    
    If Range("F21").Value = "Hospedado" Then
    Range("F21", "X21").Value = ""
    End If
    
    If Range("F22").Value = "Hospedado" Then
    Range("F22", "X22").Value = ""
    End If
    
    If Range("F23").Value = "Hospedado" Then
    Range("F23", "X23").Value = ""
    End If
    
    End Sub
    
    
    And so on... if I continue with this code 150 times down I have solved my problem, however, there must be a simpler way to do it? I've tried this and it does NOT work...
    
    Private Sub CommandButton1_Click()
    
    If Range("F21":"F170").Value = "Hospedado" Then
    Range("F21", "X170").Value = ""
    End If
    
    End Sub
    
    Any ideas?

    Thanks and regards,
    Andreas B.
    Last edited by odin78; 04-03-2016 at 02:04 PM.

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: I need to create a reset button that will reset rows containing a specific value

    Hi Andreas

    See if this works for you...
    Option Explicit
    
    Private Sub CommandButton1_Click()
       Dim Rng          As Range
       Dim cel          As Range
       Dim LR           As Long
    
       With ActiveSheet
          LR = .Range("F" & .Rows.Count).End(xlUp).Row
          Set Rng = .Range("F21:F" & LR)
          For Each cel In Rng
             If cel.Value = "Hospedado" Then
                cel.Value = ""
                .Cells(cel.Row, "X").Value = ""
             End If
          Next cel
       End With
    End Sub
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

+ 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. Create running stopwatch/timer with 1 button (start/stop). No reset button.
    By leeroy2612 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-26-2021, 12:59 AM
  2. [SOLVED] Reset Button
    By Mick Hassell in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2015, 04:58 AM
  3. [SOLVED] Double click a cell to copy it to another cell & how to create a reset button in excel
    By jjin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-02-2013, 10:10 AM
  4. Reset Button
    By BJbeans in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-13-2012, 02:26 PM
  5. Create a clear/reset "button"?
    By splenguin in forum Excel General
    Replies: 10
    Last Post: 09-03-2009, 06:12 PM
  6. Reset Button
    By Laker555 in forum Excel General
    Replies: 1
    Last Post: 08-02-2007, 07:05 AM
  7. Reset Button
    By Laker555 in forum Excel General
    Replies: 0
    Last Post: 08-01-2007, 12:33 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