Editing Macros

Copper Contributor

I had someone create the Macro below and now the source doc has 3 additional columns and I can't figure out how to edit it to account for them. It simply takes a list of products, in the first sheet of the work book and copies each unique row the number in the 9th column (I). The spreadsheet now has 3 additional columns so it will now be the 12th column (L).

-------

Sub Label()
Dim i As Long, j As Long, k As Long, m As Long

With Worksheets(1)
i = InputBox("Enter the number of the column that contains the quantities.")
For j = .Range("A1").CurrentRegion.Rows.Count To 2 Step -1
For k = 1 To .Range("a1").Offset(j - 1, i - 1).Value - 1
.Cells(j, 1).EntireRow.Insert
For m = 1 To .Range("A1").CurrentRegion.Columns.Count
.Cells(j, m).Value = .Cells(j + k, m).Value
Next m
Next k
Next j
End With
End Sub

--------------------

Pretty basic but would appreciate the help. 

 

Thanks

 

2 Replies

@TCJC2506

 

Hi,

 

According to the line below, I think that the code already takes any new column into account, as it's going through each column in the current region, not to a fixed number of columns.

For m = 1 To .Range("A1").CurrentRegion.Columns.Count

 

Could you provide a sample of the data that you work on, to apply the code on it and figure out the issue?

@Haytham Amairah Thanks, I assumed it had to do with the added columns but it looks like the issue was a blank column header. Appreciate your reply