+ Reply to Thread
Results 1 to 7 of 7

Adding control box to VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Adding control box to VBA

    I'd like to make this macro interactive by adding a box to select column and text with wildcards
    Currently I change the "F" and the "*:*" in the code below and then run the macro. But, I'd like to make it interactive so others with no experience with vba can do it.

    Any help greatly appreciated.

    Jim

    rows in macro that are affected
    With .Cells(Lrow,"F") ‘insert column
    If Not IsError(.Value) Then
    If .Value Like "*:*" Then .E. . . .


    Sub Delete_Row_IfCellContainsCertainText ()
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
        With ActiveSheet
            .Select
    
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
            .DisplayPageBreaks = False
    
            Firstrow = .UsedRange.Cells(1).Row
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
            For Lrow = Lastrow To Firstrow Step -1
                With .Cells(Lrow,"F") ‘insert column
                    If Not IsError(.Value) Then
                        If .Value Like "*:*" Then .EntireRow.Delete ‘insert common text with wildcard
                    End If
                End With
            Next Lrow
        End With
     
        ActiveWindow.View = ViewMode
        With Application
            .ScreenUpdating = True
            .Calculation = CalcMode
        End With
    End Sub

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: Adding control box to VBA

    Hi Jim,

    How about using an InputBox and ask what column Letter to look in for stuff to delete? Save this variable and use in place of your "F" in your code.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Re: Adding control box to VBA

    Thanks for the response Marvin
    I'm not great with VBA - I try to find working code to our applications and then string codes together. I've not created an Input box for this type of application. Could you help me out with the how.
    Input Column & Input text to look for (if text found delete row)

    Thanks again

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: Adding control box to VBA

    Try this

    Sub Delete_Row_IfCellContainsCertainText()
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
        Dim ColumnLetter As String
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
        With ActiveSheet
            .Select
    
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
            .DisplayPageBreaks = False
    
            Firstrow = .UsedRange.Cells(1).Row
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
            ColumnLetter = InputBox("What Column do you want to look in?")
            For Lrow = Lastrow To Firstrow Step -1
                With .Cells(Lrow, ColumnLetter)
                    If Not IsError(.Value) Then
                        If .Value Like "*:*" Then .EntireRow.Delete
                    End If
                End With
            Next Lrow
        End With

  5. #5
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Re: Adding control box to VBA

    Thanks Marvin - this part works great but need input box to declare this line
    If .Value Like "*:*" Then .EntireRow.Delete

    The *:* could be anything desired - so how could I incorporate that query?

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,228

    Re: Adding control box to VBA

    Same idea
    Sub Delete_Row_IfCellContainsCertainText()
        Dim Firstrow As Long
        Dim Lastrow As Long
        Dim Lrow As Long
        Dim CalcMode As Long
        Dim ViewMode As Long
        Dim ColumnLetter As String
        Dim LookFor As String
    
        With Application
            CalcMode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
        With ActiveSheet
            .Select
    
            ViewMode = ActiveWindow.View
            ActiveWindow.View = xlNormalView
            .DisplayPageBreaks = False
    
            Firstrow = .UsedRange.Cells(1).Row
            Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row
            ColumnLetter = InputBox("What Column do you want to look in?")
            LookFor = InputBox("What do you want to delete?")
            For Lrow = Lastrow To Firstrow Step -1
                With .Cells(Lrow, ColumnLetter)
                    If Not IsError(.Value) Then
                        If .Value Like "*" & LookFor & "*" Then .EntireRow.Delete
                    End If
                End With
            Next Lrow
        End With
    End Sub

  7. #7
    Forum Contributor
    Join Date
    07-17-2015
    Location
    Roanoke, Virginia
    MS-Off Ver
    2010
    Posts
    173

    Re: Adding control box to VBA

    This is sweat Marvin - works like a charm in so many ways. Can't thank you enough
    Jim

+ 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. adding a vba search code to a button control
    By vickyp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-30-2013, 09:07 AM
  2. Adding Form Control Buttons
    By wildlifegis in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2012, 01:55 AM
  3. Adding a Control Caption
    By redux112358 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-15-2009, 03:16 PM
  4. Adding Control to a Dynamic Listbox
    By ben_sumner in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-06-2007, 07:53 PM
  5. Adding the VB Timer Control...
    By Dinesh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2006, 10:10 PM
  6. Adding a control to a User Form
    By scantor145 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2005, 05:05 PM
  7. [SOLVED] Adding Button to Popup Control
    By trooper665 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-08-2005, 02:05 PM
  8. Adding a Control programatically
    By Richard Buttrey in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-05-2005, 04:05 AM

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