Hi all experts.
I have a macro that is designed to copy cells based on a cell value. I need help to select the range of what needs to be copied. Now it only copies content from column "F". I need to be able to select multiple columns - "F" & "K" & "I".
Here is the macro as of today.
Sub CopyToColumnB()
Dim LRow As Integer
Dim LQty As Integer
Dim LProduct As String
Dim LColCPosition As Integer
Dim j As Integer
Dim LStart As Integer
Dim LEnd As Integer
'Search for values in column B starting at row 2
LRow = 1
'Copy values to column C starting at row 2
LColCPosition = 1
'Search through values in column B until a blank cell is encountered
While Len(Range("A" & CStr(LRow)).Value) > 0
'Retrieve quantity and product name
LQty = Range("L" & CStr(LRow)).Value
LProduct = Range("F" & CStr(LRow)).Value
'Set start and end position for copy to column C
LStart = LColCPosition
LEnd = LColCPosition + LQty
'Copy product name the number of times that is given by the quantity
For j = LStart To LEnd - 1
Range("B" & CStr(j)).Value = LProduct
Next
'Update column C position
LColCPosition = LEnd
LRow = LRow + 1
Wend
MsgBox "Column B has been populated."
End Sub
Start Free Trial