Replace slash with a dash after meeting one criteria

HankJ

Board Regular
Joined
Mar 5, 2016
Messages
89
Hi
I have some code that works, it appears to do the job after some trail and error.
I'm pretty new to excel VBA and would like to ask about improving the code.
I have three columns of data copied from another sheet.
Two columns of data, columns B and C, are then merged in column D separated by a slash.
For some projects, those in column A starting LLL, the slash needs to be a dash.

Excel 2010
A
'Add the compound list to the plate builder
Dim CmpdListEnd As Long
CmpdListEnd = Workbooks(WeeklySheet).Worksheets("Compound List").Range("A1").End(xlDown).Row
ThisWorkbook.Worksheets("Compound List").Range("A1:C" & CmpdListEnd).Value = Workbooks(WeeklySheet).Worksheets("Compound List").Range("A1:C" & CmpdListEnd).Value
ThisWorkbook.Worksheets("Compound List").Range("D2:D" & CmpdListEnd).FormulaR1C1 = "=if(RC[-1]=" & Chr(34) & Chr(34) & ",RC[-2],RC[-2]&" & Chr(34) & " / " & Chr(34) & "&RC[-1])"
ThisWorkbook.Worksheets("Compound List").Range("D2:D" & CmpdListEnd).Value = ThisWorkbook.Worksheets("Compound List").Range("D2:D" & CmpdListEnd).Value
Code to replace "/" with "-" for LLL projects
Dim PltBld As Workbook
Dim CmpLst As Worksheet
Set PltBld = Workbooks("Plate builder LLL.xlsm")
Set CmpLst = PltBld.Sheets("Compound List")
CmpLst.Activate
Dim I As Integer
For I = 2 To CmpdListEnd
If Left(CmpLst.Cells(I, 1), 3) = "LLL" Then 'Looking for LLL in column A
CmpLst.Cells(I, 4).Replace What:="/", Replacement:="-", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
End If
Next I
Range("A1").Select

<tbody>
[TD="align: center"]75[/TD]

[TD="align: center"]76[/TD]

[TD="align: center"]77[/TD]

[TD="align: center"]78[/TD]

[TD="align: center"]79[/TD]

[TD="align: center"]80[/TD]

[TD="align: center"]81[/TD]
[TD="align: right"][/TD]

[TD="align: center"]82[/TD]

[TD="align: center"]83[/TD]

[TD="align: center"]84[/TD]

[TD="align: center"]85[/TD]

[TD="align: center"]86[/TD]

[TD="align: center"]87[/TD]

[TD="align: center"]88[/TD]

[TD="align: center"]89[/TD]

[TD="align: center"]90[/TD]

[TD="align: center"]91[/TD]

[TD="align: center"]92[/TD]

[TD="align: center"]93[/TD]

[TD="align: center"]94[/TD]

[TD="align: center"]95[/TD]

</tbody>
LLL replace project
Two questions:
Is this the correct/best way to reference ranges? I'm still learning about referencing specific workbooks/worksheets. The reason I went to SET, is that when I first inserted the code from Line 82, it processed the original worksheet and made a real mess of some equations.

Are the 13 lines of code inserted needed there? Could I add if loop after line 78 to read the project code in column A before merging columns B and C with either a dash or a slash?

Many thanks

Hj
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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