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
<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>
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
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