Hi Alan,
Sorry for my confusive explanation.
This is how the file looks before VBA Copy parts of array - MacroWorkbook Before.xlsm
This is how the file should look after VBA Copy parts of array - MacroWorkbook After.xlsm
I need when the "Run macro" button will be clicked, a popup menu to appear that will allow the user to insert number of months (month period).
The standard months that exist are shown in the "Standard Months range" sheet, in file "VBA Copy parts of array - MacroWorkbook After".
The conditions that the macro will need to follow are the following:
a) If the entered month value is equal to a value that already exist in the list, message should appear that will notify the user that the given value already exist in the list, and no future action will be taken.
b) If a value which is not in the list is chosen, then the macro should search the first lower value in column "E" and all rows (columns B, C, D, F, G, H) which have this value to be copied at the end of the table.
c) In the column E to be inserted the newly chosen month period value.
d) In column A to be filled the serial number for the row.
In the file "VBA Copy parts of array - MacroWorkbook After", the new inserted rows are at the end, marked with yellow.
The data for the value where in column E we have 22 corresponds with the data where for column E we have 12.
The data for the value where in column E we have 41 corresponds with the data where for column E we have 36.
The data for the value where in column E we have 75 corresponds with the data where for column E we have 72.
I've wrote a code that fulfills the macro conditions b) and d).
Sub test()
Dim rcnt As Long
rcnt = Range("A" & Rows.Count).End(xlUp).Row
For i = 1 To rcnt
If Range("E" & i).Value = "12" Then ' change the number (22) which represents the month period
Range("B" & i).Copy
Range("B" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
Range("C" & i).Copy
Range("C" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
Range("D" & i).Copy
Range("D" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
Range("E" & i).Value = 12 ' change the number (22) which represents the month period
Range("F" & i).Copy
Range("F" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
Range("G" & i).Copy
Range("G" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
Range("H" & i).Copy
Range("H" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial xlPasteAll
End If
Next i
Application.CutCopyMode = False
' Add numbers in column A
For x = 1 To Range("a6").CurrentRegion.Rows.Count - 1
Range("A" & x + 1) = x
Next x
End Sub
But I need the macro to be able to fulfill the conditions a) and c).
When you click the "Run macro" button, the input form will appear in which the user will need to insert the month range value.
Hope this was clearer that the previous post.
Please let me know in case I need better to explain.
Thank you in advance.
Igor
Bookmarks