I am trying to merge these two scripts together and it's not working. Ideally, I would like to merge multiple scripts together.
Also, do I insert these as a module or right in the VBA sheet?
Also, do I insert these as a module or right in the VBA sheet?
VBA Code:
Sub DataSplit_array_formulas()
Dim sht As Worksheet
Dim rng As Range
Dim arrSrc As Variant, arrOut As Variant
Dim lastRow As Long
Dim splitCell As Variant, splitColNo As Long
Dim maxLines As Long
Dim i As Long, j As Long, iCol As Long, rowOut As Long
Dim myRange As Range
Set sht = Worksheets("Sheet1")
With sht
lastRow = .Cells(Rows.Count, 1).End(xlUp).Row
Set rng = .Range(.Cells(4, "A"), .Cells(lastRow, "Z"))
splitColNo = 19
arrSrc = rng.FormulaR1C1
End With
' Based on the number of Line Feeds get the count to dimension the output array
For i = 1 To UBound(arrSrc)
' If delimiter is comma+space convert it to vbLF to standardise the delimiter.
arrSrc(i, splitColNo) = Replace(arrSrc(i, splitColNo), ", ", vbLf)
maxLines = maxLines + (Len(arrSrc(i, splitColNo)) - Len(Replace(arrSrc(i, splitColNo), vbLf, "")) + 1)
Next i
ReDim arrOut(1 To maxLines + UBound(arrSrc), 1 To UBound(arrSrc, 2)) ' Added UBound(arrSrc) to allow for blank rows
For i = 1 To UBound(arrSrc)
splitCell = Split(arrSrc(i, splitColNo), vbLf)
For j = LBound(splitCell) To UBound(splitCell)
rowOut = rowOut + 1
For iCol = 1 To UBound(arrSrc, 2)
arrOut(rowOut, iCol) = arrSrc(i, iCol) ' should skip column 19 but it will get overwritten anyway
Next iCol
arrOut(rowOut, splitColNo) = splitCell(j)
Next j
rowOut = rowOut + 1 ' Insert Blank Row
Next i
rng.Resize(rowOut, UBound(arrOut, 2)).Value = arrOut
Merge With
' Find lastRow in column S
lastRow = Cells(Rows.Count, "S").End(xlUp).Row
' Set range to look at
Set myRange = Range("S4:S" & lastRow)
' Replace 007,
myRange.Replace What:="007", Replacement:="JamesBond", LookAt:=xlWhole, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False