VBA Code Question: Finding Series of Data & Removing It (Please read igold)

DRomito

New Member
Joined
Nov 11, 2015
Messages
5
The original thread got ALL messed up. Anywho attached is a screen of the data I'm working with. Below that is the code I've written along with your segment placed into it. I've updated yours to represent column B and it's running an infinite loop and not removing anything. Any suggestions?

Screenshot_111615_030413_PM_zpsvjv3uxts.jpg


Here is the code:
Code:
Sub Create_List2()
'
' Create_List2 Macro
'


'Copy Formula tab to List
    Sheets("List").Select
    Columns("A:A").ClearContents
    Sheets("Formula").Select
    Columns("A:A").Select
    Selection.Copy
    Sheets("List").Select
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
'Find and Replace blanks
    Selection.Replace What:="", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    
    Call Work_Off_This
    
    Selection.SpecialCells(xlCellTypeBlanks).Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlUp

Your snippet updated to column B:
Code:
Sub Work_Off_This()


    Dim dat1 As String
    Dim dat2 As String
    Dim lrow As Long, i As Long, x As Long
    
    lrow = Cells(Rows.Count, 2).End(xlUp).Row
    For i = 1 To lrow
        If Cells(i, 2) = "" Then GoTo Blnk
        dat1 = Cells(i, 2).Value
        If Cells(i + 1, 2).Value = "" Then GoTo Blnk
        dat2 = Cells(i + 1, 2).Value
            For x = i + 2 To lrow
                If Cells(x, 2).Value = dat1 And Cells(x + 1, 2) = dat2 Then
                    Cells(x, 2).ClearContents
                    Cells(x + 1, 2).ClearContents
                End If
            Next
Blnk:
  Next
  
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hard to say from what I am seeing. My first thought would to make sure that before you call my code you make sure that the activesheet is the sheet on which you want my code to run. I have set a definitive value for my For Next loop, so it should not be running infinitely. Alternatively you could just add additional code to my code to make the correct sheet the activesheet.

Additionally, I believe your code was written with the Macro Recorder. We could clean that up quite a bit, and it would a lot more efficient...

igold
 
Upvote 0
Alrighty... I was playing around with this and it appears to select the wrong points of data. In this instance I need it to select the "/tr" and the "tr expanded=true" and remove every instance of that. Thoughts?

We can worry about efficiency once this little bugger works.
 
Upvote 0

Forum statistics

Threads
1,216,225
Messages
6,129,604
Members
449,520
Latest member
TBFrieds

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top