데이터:
다음 표가 있습니다.
160 89 85 116 161
147 117 133 148 191
93 91 94 92 107
147 148 177 133 205
116 147 117 190 148
문제:
데이터를 단일 열로 병합하고 싶습니다.
버튼을 통해 실행되는 단일 행에 대한 코드입니다.
암호:
Sub mergeStuff()
Range("M3").Value = CStr(Range("H3").Value) + "," + CStr(Range("I3").Value) + "," + CStr(Range("J3").Value) + "," + CStr(Range("K3").Value) + "," + CStr(Range("L3").Value)
End Sub
출력 예 :
160,89,85,116,161
147,117,133,148,191
93,91,94,92,107
147,148,177,133,205
116,147,117,190,148
질문:
숫자는 형식이 지정됩니다. 색상이 다릅니다. 하나의 셀에서 병합하고 색상 서식을 유지하려면 어떻게해야합니까?
이 코드는 색상 값을 저장하고 셀을 연결 한 다음 저장된 색상 값을 기반으로 문자열의 색상을 지정합니다. 는 1 to 5
당신이 합치되는 열 수를 반영하도록 변경해야합니다. 귀하의 예에는 5 개의 열이 있습니다. 1 to 3
일부는 방치 할 수있다.
Sub mergeStuff()
Dim arrColors(1 To 5, 1 To 3) As Long
Dim rIndex As Long
Dim cIndex As Long
Dim StartColor As Long
Dim strOutput As String
Dim i As Long
For rIndex = 3 To Cells(Rows.Count, "H").End(xlUp).Row
StartColor = 1
strOutput = vbNullString
For cIndex = Columns("H").Column To Columns("L").Column
strOutput = strOutput & "," & Cells(rIndex, cIndex).Value
arrColors(cIndex - Columns("H").Column + 1, 1) = StartColor
arrColors(cIndex - Columns("H").Column + 1, 2) = Len(Cells(rIndex, cIndex).Value)
arrColors(cIndex - Columns("H").Column + 1, 3) = Cells(rIndex, cIndex).Font.Color
StartColor = StartColor + Len(Cells(rIndex, cIndex).Value) + 1
Next cIndex
With Cells(rIndex, "M")
.Value = Mid(strOutput, 2) 'Remove beginning comma
For i = 1 To UBound(arrColors, 1)
.Characters(arrColors(i, 1), arrColors(i, 2)).Font.Color = arrColors(i, 3)
Next i
End With
Next rIndex
End Sub
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다