VBA Code - add sheet with previous sheet name and suffix

horizonflame

Board Regular
Joined
Sep 27, 2018
Messages
184
Office Version
  1. 2013
Hi AllI'm filtering on column I and creating a new sheet to move the contents too. I need to rename the sheet as the previous sheet name with the criteria suffix. Could somebody help me please with the last part of my code?

Thanks

Code:
Range("I1").Select    
Selection.AutoFilter    
ActiveSheet.Range("$A$1:$L$231").AutoFilter Field:=9, Criteria1:="=01***", _        
Operator:=xlOr, Criteria2:="=02***"

'take sheet name and add suffix _0102    
Sheets.Add(After:=Sheets(Sheets.Count)).Name =     
ActiveSheet.Paste
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
By "previous sheet" do you mean the one to the left of the new sheet, or something else?
 
Upvote 0
How about
Code:
Sub horizonflame2()
   Dim ShtName As String
   With ActiveSheet
      If .AutoFilterMode Then .AutoFilterMode = False
      .Range("$A$1:$L$231").AutoFilter Field:=9, Criteria1:="=01***", _
         Operator:=xlOr, Criteria2:="=02***"
      .AutoFilter.Range.Copy
      ShtName = .name
   End With
   'take sheet name and add suffix _0102
   Sheets.Add(After:=Sheets(Sheets.Count)).name = ShtName & "_0102"
   ActiveSheet.paste
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,744
Messages
6,126,621
Members
449,322
Latest member
Ricardo Souza

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