Combining 3 macros into one

linaeum66

New Member
Joined
Jul 2, 2017
Messages
25
Would it be possible to combine the following two macros into a single macro? Thanks in advance.


Sub DelRows()
Application.ScreenUpdating = False
Dim LastRow As Long
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Range("A1:A" & LastRow).AutoFilter Field:=1, Criteria1:="*II*"
Range("A2:A" & LastRow).SpecialCells(xlCellTypeVisible).EntireRow.Delete
If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
Application.ScreenUpdating = True
End Sub


----------------------------------------------------------------------------------------------------

<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff }
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #011993 ; background-color: #ffffff }
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; background-color: #ffffff ; min-height: 13.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 ; background-color: #ffffff ; min-height: 13.0px}
span.s1 {color: #011993 }
span.s2 {color: #000000 }
</style>


Sub RemoveSingles()

Dim lr As Long, MyList As Variant, i As Long, Names As Variant, j As Long







lr = Cells(Rows.Count, "A").End(xlUp).Row

MyList = Range("A2:A" & lr).Value

For i = 1 To UBound(MyList)

Names = Split(MyList(i, 1), ",")

For j = 0 To UBound(Names)

If InStr(Trim(Names(j)), " ") = 0 Then Names(j) = "|"

Next j

MyList(i, 1) = Replace(Replace(Join(Names, ","), "|,", ""), "|", "")

Next i

Range("A2:A" & lr).Value = MyList



End Sub
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You could (just copy the VBA code block from the one and place it under the other), or you could simply leave it as is and call one from the other (or create one macro that calls both and run that instead), i.e.
Code:
Sub MyMainMacro
    Call DelRows
    Call RemoveSingles
End Sub
This is a very common technique, to keep your macros shorter (and more numerous) and just call them as you need them.
One nice thing about that is if you have some code that you have to run more than once in your code, you don't need to create the whole code a second time.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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