Patriot2879
Well-known Member
- Joined
- Feb 1, 2018
- Messages
- 1,259
- Office Version
- 2010
- Platform
- Windows
This code works great with removing the duplicates in Sheet2, and putting what is left into a cell in sheet1, but it does not work if i copy and paste cells from another worksheet into sheet2, different cells are left blank in sheet1. Hope you can help me please? I have this code duplicated alot for different cells to paste into.
VBA Code:
Define variables for each cell value
Dim valueB As String
Dim valueC As String
Dim valueD As String
Dim valueE As String
Dim valueF As String
' Store values from Sheet2, cells A3 to E3 into variables
With Worksheets("Sheet2")
valueB = .Range("B2").Value
valueC = .Range("C2").Value
valueD = .Range("D2").Value
valueE = .Range("E2").Value
valueF = .Range("F2").Value
' Initialize concatenatedValue as empty string
Dim concatenatedValue As String
concatenatedValue = ""
' Check each value and concatenate with "/" if not empty
If valueB <> "" Then
concatenatedValue = valueB
End If
If valueC <> "" Then
If concatenatedValue <> "" Then
concatenatedValue = concatenatedValue & " / " & valueC
Else
concatenatedValue = valueC
End If
End If
If valueD <> "" Then
If concatenatedValue <> "" Then
concatenatedValue = concatenatedValue & " / " & valueD
Else
concatenatedValue = valueD
End If
End If
If valueE <> "" Then
If concatenatedValue <> "" Then
concatenatedValue = concatenatedValue & " / " & valueE
Else
concatenatedValue = valueE
End If
End If
If valueF <> "" Then
If concatenatedValue <> "" Then
concatenatedValue = concatenatedValue & " / " & valueF
Else
concatenatedValue = valueF
End If
End If
' Put the concatenated value into cell A4 on Sheet1
Worksheets("Sheet1").Range("A2").Value = concatenatedValue