1

here's the code I currently have in VBA (Excel) at the moment. Most of it has come from macro recordings that I've made. What I'm looking for is to be able to insert for example, row 10 as just 10 in the inputbox without having to put it in as 10:10. Is there a way for me to edit my current code to allow this? I've tried using Rows("TargetRow:TargetRow") but that gives odd results.

Dim TargetRow As Variant
TargetRow = InputBox("Insert row # where data should be inserted. This should take the format XX:XX (e.g. 90:90 for row 90)", "All Industries Row", "XX:XX")

wbThis = ThisWorkbook.Name
Windows(wbThis).Activate
    Rows(TargetRow).Select
    Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromAbove

Windows("otherworksheet.xlsx").Activate
    Range("A119:J119").Select
    Application.CutCopyMode = False
    Selection.Copy
    Windows(wbThis).Activate
    Range(TargetRow).Select
    Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
        xlNone, SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False

2 Answers 2

1

Use following sub to select rows using inputbox

Sub SelectRow()
    Dim lnRow As Long
     lnRow = InputBox("Enter Row number.", "Row Input")
    Rows(lnRow & ":" & lnRow).Select
End Sub
Sign up to request clarification or add additional context in comments.

1 Comment

This sub will select rows taking input from Inputbox() Then adjust this sub with your codes.
0

If you need a Range from user input, the simplest way is to use the Excel version Application.InputBox with a type of '8' (see the documentation here).

Dim TargetRow As Range
Set TargetRow = Application.InputBox("Select the row where data should be inserted.", _
                                     "All Industries Row", , , , , , 8)
Debug.Print TargetRow.Address

Note that you should probably also get rid of the Select and Activate calls and use your object references directly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.