Home

Editing Macros

%3CLINGO-SUB%20id%3D%22lingo-sub-816043%22%20slang%3D%22en-US%22%3EEditing%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-816043%22%20slang%3D%22en-US%22%3E%3CP%3EI%20had%20someone%20create%20the%20Macro%20below%20and%20now%20the%20source%20doc%20has%203%20additional%20columns%20and%20I%20can't%20figure%20out%20how%20to%20edit%20it%20to%20account%20for%20them.%20It%20simply%20takes%20a%20list%20of%20products%2C%26nbsp%3Bin%20the%20first%20sheet%20of%20the%20work%20book%20and%20copies%20each%20unique%20row%20the%20number%20in%20the%209th%20column%20(I).%20The%20spreadsheet%20now%20has%203%20additional%20columns%20so%20it%20will%20now%20be%20the%2012th%20column%20(L).%3C%2FP%3E%3CP%3E-------%3C%2FP%3E%3CP%3ESub%20Label()%3CBR%20%2F%3EDim%20i%20As%20Long%2C%20j%20As%20Long%2C%20k%20As%20Long%2C%20m%20As%20Long%3C%2FP%3E%3CP%3EWith%20Worksheets(1)%3CBR%20%2F%3Ei%20%3D%20InputBox(%22Enter%20the%20number%20of%20the%20column%20that%20contains%20the%20quantities.%22)%3CBR%20%2F%3EFor%20j%20%3D%20.Range(%22A1%22).CurrentRegion.Rows.Count%20To%202%20Step%20-1%3CBR%20%2F%3EFor%20k%20%3D%201%20To%20.Range(%22a1%22).Offset(j%20-%201%2C%20i%20-%201).Value%20-%201%3CBR%20%2F%3E.Cells(j%2C%201).EntireRow.Insert%3CBR%20%2F%3EFor%20m%20%3D%201%20To%20.Range(%22A1%22).CurrentRegion.Columns.Count%3CBR%20%2F%3E.Cells(j%2C%20m).Value%20%3D%20.Cells(j%20%2B%20k%2C%20m).Value%3CBR%20%2F%3ENext%20m%3CBR%20%2F%3ENext%20k%3CBR%20%2F%3ENext%20j%3CBR%20%2F%3EEnd%20With%3CBR%20%2F%3EEnd%20Sub%3C%2FP%3E%3CP%3E--------------------%3C%2FP%3E%3CP%3EPretty%20basic%20but%20would%20appreciate%20the%20help.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-816043%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-819310%22%20slang%3D%22en-US%22%3ERe%3A%20Editing%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-819310%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F396268%22%20target%3D%22_blank%22%3E%40TCJC2506%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAccording%20to%20the%20line%20below%2C%20I%20think%20that%20the%20code%20already%20takes%20any%20new%20column%20into%20account%2C%20as%20it's%20going%26nbsp%3Bthrough%20each%20column%20in%20the%20current%20region%2C%20not%20to%20a%20fixed%20number%20of%20columns.%3C%2FP%3E%3CPRE%3EFor%20m%20%3D%201%20To%20.Range(%22A1%22).CurrentRegion.Columns.Count%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECould%20you%20provide%20a%20sample%20of%20the%20data%20that%20you%20work%20on%2C%20to%20apply%20the%20code%20on%20it%20and%20figure%20out%20the%20issue%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-820090%22%20slang%3D%22en-US%22%3ERe%3A%20Editing%20Macros%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-820090%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F35679%22%20target%3D%22_blank%22%3E%40Haytham%20Amairah%3C%2FA%3E%26nbsp%3BThanks%2C%20I%20assumed%20it%20had%20to%20do%20with%20the%20added%20columns%20but%20it%20looks%20like%20the%20issue%20was%20a%20blank%20column%20header.%20Appreciate%20your%20reply%3C%2FP%3E%3C%2FLINGO-BODY%3E
TCJC2506
New 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

Related Conversations
Extentions Synchronization
ChirmyRam in Discussions on
3 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
35 Replies
flashing a white screen while open new tab
Deleted in Discussions on
14 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies