BuzzOffSweetheart
New Member
- Joined
- Feb 27, 2009
- Messages
- 18
I am trying to make a macro that will:
Then as far as the advanced part:
I need to add to the code some way to take the newly pasted rows from no. 3 above and change the value of Column 4 to "new".
Here is my first attempt at the code:
The problem I am running into with the above code is it is not pasting the rows directly under the selected row - now matter how I have tried it, it wants to paste elsewehere as rRange isn't working in my code - How do i specify the rRange so it copy and inserts directly below the select cell/row?
So then I tried another approach:
Now it is pasting over data already in the worksheet instead of inserting it.. and it seems to be only pasting 2 if the user specifies 3.. 4 if user specifies 5.. etc. etc..
And I am still having trouble figuring out how to select the row newly pasted to change a column's value..
Any help please?
My code is very convoluted I am sure and I am a beginner
.. My apologies.. any help would be swell!
- Ask the user to select a Tag number (one cell in column 5 of the ws)
- Then ask the user to select the amount of detail tags to add (to copy the entire row based on their input)
- Then take that original Tag in column 5 and Select the entire row and copy it whatever amount of times was inputted from the user on number 2 above.
Then as far as the advanced part:
I need to add to the code some way to take the newly pasted rows from no. 3 above and change the value of Column 4 to "new".
Here is my first attempt at the code:
Code:
[LEFT][COLOR=#333333]
[/COLOR][/LEFT]
<code style="margin: 0px; padding: 0px; font-style: inherit; ">Sub MasterTagSelect()
Dim rRange As Range
Dim lngRows As Long
lngNextRow As Long
On Error Resume Next
Application.DisplayAlerts = False
Set rRange = Application.InputBox(Prompt:= _
"Please select a Master Tag to Split.", _
Title:="SPECIFY MASTER TAG", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If rRange Is Nothing Then
Exit Sub
Else
rRange.Select
ActiveCell.EntireRow.Select
lngRows = CLng(InputBox("How many Detail Tags do you wish to insert? (Must be at least 2)"))
lngNextRow = rRange
Selection.Copy Rows(lngNextRow & ":" & lngNextRow + lngRows - 1)
On Error GoTo Finish
Finish:
If Err.Number <> 0 Then MsgBox Prompt:="Please ensure you only enter numeric values!"
End If</code>[LEFT][COLOR=#333333]
[/COLOR][/LEFT]
The problem I am running into with the above code is it is not pasting the rows directly under the selected row - now matter how I have tried it, it wants to paste elsewehere as rRange isn't working in my code - How do i specify the rRange so it copy and inserts directly below the select cell/row?
So then I tried another approach:
Code:
[LEFT][COLOR=#333333]Sub MasterTagSelect()[/COLOR][/LEFT]
<code style="margin: 0px; padding: 0px; font-style: inherit; ">Dim rRange As Range
Dim lngRows As Long
On Error Resume Next
Application.DisplayAlerts = False
Application.ScreenUpdating = True
Set rRange = Application.InputBox(Prompt:= _
"Please select a Master Tag to Split.", _
Title:="SPECIFY MASTER TAG", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If rRange Is Nothing Then
Exit Sub
Else
rRange.Select
ActiveCell.EntireRow.Select
userInput = Application.InputBox(Prompt:="How many Detail Tags do you wish to insert? (Must be at least 2)", Type:=1) t = Int(Val(userInput))
If userInput = False Then Exit Sub
With Selection
.Copy .Resize(.Rows.Count * t, .Columns.Count).Offset(0)End With
Finish: If Err.Number <> 0 Then MsgBox Prompt:="Please ensure you only enter numeric values!"
End If
End Sub</code>
And I am still having trouble figuring out how to select the row newly pasted to change a column's value..
Any help please?
My code is very convoluted I am sure and I am a beginner

Last edited: