View Single Post
 
Old 03-31-2019, 01:14 PM
p45cal's Avatar
p45cal p45cal is offline Windows 10 Office 2016
Expert
 
Join Date: Apr 2014
Posts: 948
p45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond reputep45cal has a reputation beyond repute
Default

You could have left your attachment in, it would have been useful.

A user-defined function solution.
Array-enter it (use Ctrl+Shift+Enter, not just Enter, when committing the formula to the sheet). Do this with all 4 cells selected as you enter the formula. It's not limited to 4 cells, you can have 8 cells giving you additionally ST3, ET3, ST4, ET4, or as many as you want.

The formula in the attached is:
=blah(A1:J2)

The code for the udf is (and I'm sure it could be shorter):
Code:
Function blah(myRng)
Dim zz()
yy = myRng.Value
ReDim zz(1 To UBound(yy, 2) + 1)
idx = 1
For c = LBound(yy, 2) To UBound(yy, 2)
  Select Case c
    Case 1
      If yy(2, c) <> 0 Then
        zz(idx) = yy(1, c)
        idx = idx + 1
        If yy(2, c + 1) = 0 Then
          zz(idx) = yy(1, c)
          idx = idx + 1
        End If
      End If
    Case UBound(yy, 2)
      If yy(2, c) <> 0 And yy(2, c - 1) = 0 Then
        zz(idx) = yy(1, c)
        idx = idx + 1
      End If
      If yy(2, c) <> 0 Then
        zz(idx) = yy(1, c)
        idx = idx + 1
      End If
    Case Else
      If yy(2, c) <> 0 Then
        If yy(2, c - 1) = 0 Then
          zz(idx) = yy(1, c)
          idx = idx + 1
        End If
        If yy(2, c + 1) = 0 Then
          zz(idx) = yy(1, c)
          idx = idx + 1
        End If
      End If
  End Select
Next c
For i = idx To UBound(zz)
  zz(i) = "-"
Next i
blah = zz
End Function
Attached Files
File Type: xlsm msofficeforums42102.xlsm (16.4 KB, 22 views)
Reply With Quote