paneliyadhruv
New Member
- Joined
- May 21, 2018
- Messages
- 36
Dear all experts,
I need help to move the range of input and output.
In column B start No and column C end number. Based on first macro i am able to generate serial number with common prefix from columns K to AI.
Similarly, column D start No and column E end number. Based on second macro i am able to generate serial number with common prefix from columns AL to BJ.
Now as per my requirement is to concatenate (join) the same column value based on values present in column G and H for serial No. 1 and 2, respectively.
Macro 3 used to concatenate (join) the cell value based on value present on G4 of column K and output in column - BM (need help to move range down and output from columns BN to CK based on value in column G5 to end).
Macro 4 used to concatenate (join) the cell value based on value present on H4 of column AL and output in column CN (need help to move range down and output from columns CO to DL based on value in column H5 to end).
If number generation and concatenate work together then no need to generate series.
Please find worksheet with highlighted color for each sequence of input and output.
Thank you very much in advance.
I need help to move the range of input and output.
In column B start No and column C end number. Based on first macro i am able to generate serial number with common prefix from columns K to AI.
Similarly, column D start No and column E end number. Based on second macro i am able to generate serial number with common prefix from columns AL to BJ.
Now as per my requirement is to concatenate (join) the same column value based on values present in column G and H for serial No. 1 and 2, respectively.
Macro 3 used to concatenate (join) the cell value based on value present on G4 of column K and output in column - BM (need help to move range down and output from columns BN to CK based on value in column G5 to end).
Macro 4 used to concatenate (join) the cell value based on value present on H4 of column AL and output in column CN (need help to move range down and output from columns CO to DL based on value in column H5 to end).
If number generation and concatenate work together then no need to generate series.
Please find worksheet with highlighted color for each sequence of input and output.
Thank you very much in advance.
Code:
Sub No_serial_1()With Worksheets("Sheet1")
.Activate
Dim rng As Range, d As Range, cel As Range
Dim addStr As String
Set rng = Sheet1.Range([B4], Cells(Rows.Count, "B").End(xlUp))
addStr = Sheet1.Range("A4:A4")
Set d = [j1]
For Each cel In rng
Set d = d(1, 2)
d = cel
d.AutoFill d.Resize(cel(1, 2) - cel + 1), xlFillSeries
d.Resize(cel(1, 2)).NumberFormat = addStr & 0
Next
End With
End Sub
Sub No_serial_2()
With Worksheets("Sheet1")
.Activate
Dim rng As Range, d As Range, cel As Range
Dim addStr As String
Set rng = Sheet1.Range([D4], Cells(Rows.Count, "D").End(xlUp))
addStr = Sheet1.Range("A4:A4")
Set d = [AK1]
For Each cel In rng
Set d = d(1, 2)
d = cel
d.AutoFill d.Resize(cel(1, 2) - cel + 1), xlFillSeries
d.Resize(cel(1, 2)).NumberFormat = addStr & 0
Next
End With
End Sub
Sub Concatenate_No_serial_1()
'for concatenate serail No 1
On Error Resume Next
With Sheet1
.Activate
Dim r As Long, lr As Long, nr As Long, qr As Long
Dim L&
L = Sheet1.Range("G4")
If L = 2 Then
lr = Sheet1.Cells(Rows.Count, 11).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 65) = Cells(r, 11).Text & ", " & Cells(r + 1, 11).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 3 Then
lr = Sheet1.Cells(Rows.Count, 11).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 65) = Cells(r, 11).Text & ", " & Cells(r + 1, 11).Text & ", " & Cells(r + 2, 11).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 4 Then
lr = Sheet1.Cells(Rows.Count, 11).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 65) = Cells(r, 11).Text & ", " & Cells(r + 1, 11).Text & ", " & Cells(r + 2, 11).Text & ", " & Cells(r + 3, 11).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 5 Then
lr = Sheet1.Cells(Rows.Count, 11).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 65) = Cells(r, 11).Text & ", " & Cells(r + 1, 11).Text & ", " & Cells(r + 2, 11).Text & ", " & Cells(r + 3, 11).Text & ", " & Cells(r + 4, 11).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
lr = Sheet1.Cells(Rows.Count, 11).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step 1
nr = nr + 1
Sheet1.Cells(nr, 65) = Cells(r, 11).Text '& ", " & Cells(r + 1, 65) & ", " & Cells(r + 2, 65) 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Sheet3.Columns(65).AutoFit
End If
End If
End If
End If
End With
End Sub
Sub Concatenate_No_serial_2()
'for concatenate serail No 2
On Error Resume Next
With Sheet1
.Activate
Dim r As Long, lr As Long, nr As Long, qr As Long
Dim L&
L = Sheet1.Range("H4")
If L = 2 Then
lr = Sheet1.Cells(Rows.Count, 38).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 92) = Cells(r, 38).Text & ", " & Cells(r + 1, 38).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 3 Then
lr = Sheet1.Cells(Rows.Count, 38).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 92) = Cells(r, 38).Text & ", " & Cells(r + 1, 38).Text & ", " & Cells(r + 2, 38).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 4 Then
lr = Sheet1.Cells(Rows.Count, 38).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 92) = Cells(r, 38).Text & ", " & Cells(r + 1, 38).Text & ", " & Cells(r + 2, 38).Text & ", " & Cells(r + 3, 38).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
If L = 5 Then
lr = Sheet1.Cells(Rows.Count, 38).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step L
nr = nr + 1
Sheet1.Cells(nr, 92) = Cells(r, 38).Text & ", " & Cells(r + 1, 38).Text & ", " & Cells(r + 2, 38).Text & ", " & Cells(r + 3, 38).Text & ", " & Cells(r + 4, 38).Text 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Else
lr = Sheet1.Cells(Rows.Count, 38).End(xlUp).Row 'lr = Sheet2.Cells(Rows.Count, change column input).End(xlUp).Row
For r = 1 To lr Step 1
nr = nr + 1
Sheet1.Cells(nr, 92) = Cells(r, 38).Text '& ", " & Cells(r + 1, 65) & ", " & Cells(r + 2, 65) 'Sheet3.Cells(nr, change column output) =Cells(r, change column input) & ", " & Cells(r + 1, change column input)
If Right(Sheet1.Cells(nr, 2), 1) = "," Then
Sheet1.Cells(nr, 2) = Left(Cells(nr, 2), Len(Cells(nr, 2)) - 1)
End If
Next r
Sheet3.Columns(92).AutoFit
End If
End If
End If
End If
End With
End Sub
Last edited: