Macro MsgBox Help

kermitfrog123

Board Regular
Joined
Dec 19, 2015
Messages
50
I'm hoping someone can help me?

I have recorded the below macro and have assigned to a button on my worksheet. My Macro copies information from the sales sheet and pastes into a creation sheet which is then printed. #

What I want to do is, when the user clicks the button to run the macro I would like to specify which row number is used with an input msgbox or something. In the example below you can see row 72 is being used. Information is then copied from various columns all within row 72.

Is this possible?

Many Thanks

Code:
Sub Macro4()
'
' Macro4 Macro
'

'
    Range("C72").Select
    Selection.Copy
    Sheets("Creation").Select
    Range("B3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Sales").Select
    Range("D72").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Creation").Select
    Range("B10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Sales").Select
    Range("E72").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Creation").Select
    Range("F10").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Sheets("Sales").Select
    Range("F72:H72").Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("Creation").Select
    Range("B5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
after a little editing


Sub Macro4()
'
' Macro4 Macro
'

'
Myrow = CLng(InputBox("enter Row Number"))
Cells(Myrow, 3).Select
Selection.Copy
Sheets("Creation").Select
Range("B3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sales").Select
Cells(Myrow, 4).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Creation").Select
Range("B10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sales").Select
Cells(Myrow, 5).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Creation").Select
Range("F10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Sales").Select
Range(Cells(Myrow, 6), Cells(Myrow, 8)).Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Creation").Select
Range("B5").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub



Bye
 
Upvote 0
Hi,

Another alternative might be something like this:

Code:
Sub example()
    
    Dim vArr    As Variant
    Dim lInp    As Long


    ' user prompt for row number
    lInp = Application.InputBox( _
             Prompt:="Enter row number", _
             Title:="Row", _
             Type:=1)
    
    ' get input values from cells
    vArr = Sheets("Sales").Range("C" & lInp & ":H" & lInp).Value2
    
    ' print output values to cells
    With Sheets("Creation")
        .Range("B3").Value2 = vArr(1, 1)
        .Range("B10").Value2 = vArr(1, 2)
        .Range("F10").Value2 = vArr(1, 3)
        .Range("B5").Value2 = vArr(1, 4)
        .Range("C5").Value2 = vArr(1, 5)
        .Range("D5").Value2 = vArr(1, 6)
    End With


End Sub
 
Upvote 0
Try this:
Code:
Sub Modified()
Dim ans As String
Sheets("Sales").Activate
ans = InputBox("What Row")
Cells(ans, 3).Copy Destination:=Sheets("Creation").Cells(3, 2)
Cells(ans, 4).Copy Destination:=Sheets("Creation").Cells(10, 2)
Cells(ans, 5).Copy Destination:=Sheets("Creation").Cells(10, 6)
Range("F" & ans & ":H" & ans).Copy Destination:=Sheets("Creation").Cells(5, 2)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,016
Members
448,936
Latest member
almerpogi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top