Concatenate

rsutton1981

New Member
Joined
Mar 9, 2016
Messages
47
Office Version
  1. 365
Platform
  1. Windows
I have a sheet called "Risk Selection"; in Column A6 down you select a 'Risk Item', that then brings up the 'risk elements' (Column C). Once selected, hitting the start button the code below then searches for any reference in a sheet called "database" and copies it to the a sheet called "risk assessment". The code for this is below and works perfectly.
It is possible that a 'risk element' may appear several times depending on whether if it appears under different "risk items". for example asbestos is listed under several risk items. What I want to do is copy the 'risk item' name (Column A) and paste it to the "risk assessment" column A with the associated data from the code below.

Where there are multiple copies of the 'risk element' under different 'risk items' I want the code to concatenate the 'risk items' so there are not duplicates in the risk assessment sheet.

VBA Code:
Sub search()
   Dim Dic As Object
   Dim Cl As Range
   Dim wsRA As Worksheet
   
   Set wsRA = Sheets("Risk Assessment")
   Set Dic = CreateObject("scripting.dictionary")
   With Sheets("Database")
      For Each Cl In .Range("B2", .Range("B" & Rows.Count).End(xlUp))
         If Not Dic.Exists(Cl.Value) Then
            Dic.Add Cl.Value, Cl
         Else
            Set Dic(Cl.Value) = Union(Cl, Dic(Cl.Value))
         End If
      Next Cl
   End With
   With Sheets("Risk Selection")
      For Each Cl In .Range("B6", .Range("B" & Rows.Count).End(xlUp))
         If Dic.Exists(Cl.Value) Then
          Dic(Cl.Value).EntireRow.Copy wsRA.Range("B" & Rows.Count).End(xlUp).Offset(1, -1)
         End If
      Next Cl
   End With
End Sub
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
That is not why you have had no reply - I read your post and had no idea what you were referring to
You can see the data, we can't. It is also familiar to you.
Someone may reply if you supply the sample data from the various sheets with examples of the selections you are making and expected results
Here's the tool to do that
XL2BB - Excel Range to BBCode
 
Upvote 0
Yongle, thanks for the info about XL2BB

Risk Selection Page
CDM Risk Assessment - 2020 - V1 Draft.xlsm
ABCDEFGHIJKL
4Risk ItemRisk ElementCategoriesEnabling_Works_RelatedSite_Related
5Enabling_Works_RelatedAccess/EgressAccess/Egress
6Site_RelatedConfined SpaceAsbestos
7Enabling_Works_RelatedSurveying unstable buildings/sitesConstruction_RelatedServicesBoundary constraints
8Enabling_Works_RelatedSurveying at HeightMEP_RelatedSite ClearanceConfined Space
9Site_RelatedAsbestosOperation_Maintenance_RelatedSite InvestigationContaminated Land
10Decomission_Demolition_and_Dismantlement_RelatedSurveying at HeightDust
11New_Not_ListedSurveying unstable buildings/sitesHazardous Materials
12Temporary Service SuppliesInstallation of temporary supports
13Walkover SurveyNoise
14Site Clearance
15Utilities
16Vibration
17Weather
18Working adjacent to existing buildings
19Working on, over or adjacent to water or other liquid
20
21
22
23
24
Risk Selection
Cells with Data Validation
CellAllowCriteria
A6:A388List=Categories
B6:B388List=INDIRECT(A6)


Risk Assessment Page - with example data from current code
CDM Risk Assessment - 2020 - V1 Draft.xlsm
ABCDEFGHIJKLMNOP
1Risk ItemRisk ElementRiskWhat/Who affectedLikelihoodSeverityRiskSubjectiveDesign ControlsLikelihoodSeverityRiskSubjectivePotential other controlsActive on site (Y/N)Additional Comments (risk owner, close out evidence, etc)
2Surveying unstable buildings/sitesExisting Services (strikes)Site Users0TrivialService drawings, Existing O&M manuals155AcceptableNo instrusive works
3Surveying unstable buildings/sitesSlips, Trips and FallsIndividual0Trivial133TrivialTidy site, clear access routes
4Surveying unstable buildings/sitesUnauthorised entryAll parties0Trivial155Acceptablebarriers / fencing / hoarding, security
5Surveying unstable buildings/sitesUnstable StructuresSite Users, nearby people and structures0TrivialDo not enter155AcceptableProping, exclusion zones
6Surveying at HeightExisting Services StrikesSurveyors3412SubstantialDo not carry out intrusive investigation works. Consult existing service drawings and O&M manuals to identify existing services locations.144TrivialEnsure all known services are switched off at source prior to investigations. Scan areas to locate any hidden residual services before undertaking intrusive investigations. PPE.
Risk Assessment
Cell Formulas
RangeFormula
G2:G6,L2:L6G2=SUM(E2*F2)
H2:H6,M2:M6H2=IF(G2<5,"Trivial",IF(G2<7,"Acceptable",IF(G2<10,"Moderate",IF(G2<15,"Substantial", IF(G2<=25,"Intolerable")))))


Database Example
CDM Risk Assessment - 2020 - V1 Draft.xlsm
ABCDEFGHIJKLMNOP
1Risk ItemRisk ElementRiskWhat/Who affectedLikelihoodSeverityRiskSubjectiveDesign ControlsLikelihoodSeverityRiskSubjectivePotential other controlsActive on site (Y/N)Additional Comments (risk owner, close out evidence, etc)
2Access roofAccess/EgressOperators, site users0Trivial0Trivial
3Access roofEmissionsOperators, site users0Trivial0Trivial
4Access roofFragile roof lightOperatives, site users5525IntolerableAccess arrangement using proprietary roof hatch with companion type stair (avoid vertical ladder) arrangement to be provided.155AcceptableWorks to be carried out by competent & trained contractor. PPE equipment.
5Access roofLiftingOperatives, site users,5525Intolerable155AcceptableExclusion zones, lifting plans, trained operatives
6Access roofNoiseOperators, site users0Trivial0Trivial
7Access roofServices (strike/damage)Operators, site users, building, neighbours0Trivial0Trivial
8Access roofWorking at heightOperators, site users5525IntolerableDesign with majority of build on floor155AcceptableTraining, guard rails, specialist access equipment, fall arrest systems
9Access roofWorking on scaffoldingOperatives, site users5525Intolerable155AcceptableScaffold inspection, training, PPE
10Access windowsAccess/Egress0Trivial0Trivial
11Access windowsServices0Trivial0Trivial
DataBase
Cell Formulas
RangeFormula
G2:G11,L2:L11G2=SUM(E2*F2)
H2:H11,M2:M11H2=IF(G2<5,"Trivial",IF(G2<7,"Acceptable",IF(G2<10,"Moderate",IF(G2<15,"Substantial", IF(G2<=25,"Intolerable")))))
 
Upvote 0

Forum statistics

Threads
1,214,780
Messages
6,121,527
Members
449,037
Latest member
tmmotairi

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