[VBA] Find and replace "/" to "-"

timetabler

New Member
Joined
Jun 15, 2010
Messages
27
Using existing list of classes, which are named in the format: 8A/Cp or 13W/Ma. I can print dynamic class lists for our teachers

My existing code works well for printing, but because of the "/" (which we can't change) I can't PDF the files.

The existing code I use is a simple print and repeat:
Code:
Sub PrintfromDropDown()  Dim R As Range
  For Each R In Sheets("SIMS Classes").Range("g4:g250")
    If Not IsEmpty(R) Then
      Range("B1") = R
      ActiveSheet.PrintOut
    End If
  Next
End Sub

How (and where) would I put a find & replace the "/" within "R" variable, so that instead of printing I can pass this as a file name? e.g. 8A/CP becomes 8A-CP or 13W/Ma becomes 13W-Ma.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Use the SUBSTITUTE Function of Excel to replace "/" with "-"

Code:
Sub PrintfromDropDown()
Dim R As Range
  For Each R In Sheets("SIMS Classes").Range("g4:g250")
    If Not IsEmpty(R) Then
      Range("B1") = Application.WorksheetFunction.Substitute(R, "/", "-")
      ActiveSheet.PrintOut
    End If
  Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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