merging many deletion macros into one

neocrk

New Member
Joined
Jun 1, 2014
Messages
8
Hi Guys,

I have a large spreadsheet where I have many deletion macros - basically they are removing records that have specific value in G column).
For that I am using following macros:

Code:
Sub macro1()
Dim i As Integer
For i = 1000 To 1 Step -1
If Range("G" & i).Value = "text" Then

Range("A" & i & ":O" & i).Delete Shift:=xlUp

End If
Next i
End Sub


I have around 10 macros like the one above and then I am calling them with one button:

Code:
Sub buttonMacro()
Call macro1
Call macro2
Call macro3
Call macro4


Is it possible to merge all those macros into one and then assign only one macro to the button ? Probably that would be much more efficient that running them separately
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
So are you looking for something like this:

Rich (BB code):
Sub macro1()
Dim i As Integer
For i = 1000 To 1 Step -1
If Range("G" & i).Value = "text" Or Range("G" & i).Value = "another value" Or Range("G" & i).Value = "another value2" Or Range("G" & i).Value = "another value3" Then
Range("A" & i & ":O" & i).Delete Shift:=xlUp
End If
Next i
End Sub
Chris.
 
Upvote 0
Code:
Sub M_snb()   sn=activesheet.columns(5).specialcells(2)

  For j= 1 to ubound(
   If sn(j,1)= "text" or sn(j,1)="text_2" or sn(j,1)= "text_3" Then sn(j,1)=""
  next   
  activesheet.columns(5).specialcells(2)=sn
  activesheet.columns(5).specialcells(4).entirerow.delete End Sub</pre>
 
Upvote 0
So are you looking for something like this:

Rich (BB code):
Sub macro1()
Dim i As Integer
For i = 1000 To 1 Step -1
If Range("G" & i).Value = "text" Or Range("G" & i).Value = "another value" Or Range("G" & i).Value = "another value2" Or Range("G" & i).Value = "another value3" Then
Range("A" & i & ":O" & i).Delete Shift:=xlUp
End If
Next i
End Sub
Chris.

That is perfect Chris :D One last thing - where should I put & _ to split that code in few lines(it is very long now) - I tried in few different places but it's not working for me?
 
Upvote 0
As far as I'm aware you can put it anywhere. The syntax is just " _", i.e. space then underscore, then move to the next line.

Chris.
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

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