PDA

View Full Version : Create user input box for range row in Excel



AawwYeahh
11-06-2020, 09:37 AM
I have recorded macro to copy (A3:M3) and paste specific cells (A3:M3) to another workbooks specific cells(A3:M3).
My problem is that I would like to create a command button to do function,
BUT have the ability to change row value
IE: if I select 3 in row input box it copies cells(A3:M3)
if I select 4 in row input box it copies cells(A4:M4)
if I select 5 in row input box it copies cells(A5:M5)
the cells will ALWAYS be pasted into the same target cells in 2nd workbook (A3:M3)
any suggestions (I am trying to create a command to create an estimate from call log entry)




Sub testcopy()
'
' testcopy Macro
'


'
Range("A3:M3").Select
Selection.Copy
Windows("Mid Template rev56.xltm").Activate
Workbooks.Open Filename:= _
"C:\Users\AY\Memphis\Custom Office Templates\Mid Template rev56.xltm" _
, Editable:=True
Sheets("DASHBOARD").Select
ActiveWindow.SmallScroll Down:=-51
Range("A3:M3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Windows("(CALL LOG).xlsx").Activate
End Sub

p45cal
11-06-2020, 11:28 AM
You could try something like:
Sub testcopy()
Dim rngrw As Range
On Error Resume Next
Set rngrw = Application.InputBox("Select row", "Row Copy", Intersect(Range("A:M"), Selection.Cells(1).EntireRow).Address(0, 0), , , , , 8)
On Error GoTo 0
If Not rngrw Is Nothing Then
Set rngrw = Intersect(Range("A:M"), rngrw.Cells(1).EntireRow) 'if the user doesn't confirm default it uses the first cell in what the user selects as basis for which row columns A:M will be copied from.
rngrw.Copy
Windows("Mid Template rev56.xltm").Activate
Workbooks.Open Filename:= _
"C:\Users\AY\Memphis\Custom Office Templates\Mid Template rev56.xltm", Editable:=True
Sheets("DASHBOARD").Select
ActiveWindow.SmallScroll Down:=-51
Range("A3:M3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Windows("(CALL LOG).xlsx").Activate
Else
MsgBox "Copy operation aborted"
End If
End Sub
where an input box requests the user to select something and the user can accept the default (which is based on the currently selected cell(s)) or just use the mouse to select another range/cell, which is then used as the row from which columns A:M are copied.