Replacing fixed range to range from Input Box

m_sabeer

New Member
Joined
Sep 12, 2013
Messages
24
Ok so I have found this VBA code to copy same range from multiple sheets:

Sub MakeSummaryTable()
Dim ws As Worksheet

Application.ScreenUpdating = False
Sheets("Sheet1").Activate

For Each ws In Worksheets
If ws.Name <> "Sheet1" Then
ws.Range("A1:C3").Copy
ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
End If
Next ws

Application.ScreenUpdating = True

End Sub


Now I am wondering if I can replace ws.Range("A1:C35").Copy that has a fixed range and makes it read from an input box that pops up once the macro is run. So i manually write A1:C35 in the input box.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
try this:

Code:
Sub MakeSummaryTable()
 Dim ws As Worksheet
 
 Set Rng = Application.InputBox("Range:", Type:=8)
 
 Application.ScreenUpdating = False
 Sheets("Sheet1").Activate
 For Each ws In Worksheets
 If ws.Name <> "Sheet1" Then
 ws.Range(Rng).Copy
 ActiveSheet.Paste Range("A65536").End(xlUp).Offset(1, 0)
 End If
 Next ws
 Application.ScreenUpdating = True
 End Sub
 
Upvote 0
If you are going to manually enter the range try this.
Code:
Sub MakeSummaryTable()
Dim ws As Worksheet
Dim strAddress As String

    strAddress = InputBox("Please enter address of range to copy:", "Range to copy")
    
    If strAddress = "" Then
        MsgBox "Cancelled!", vbCritical
        Exit Sub
    End If

    Application.ScreenUpdating = False

    For Each ws In Worksheets
        If ws.Name <> "Sheet1" Then
            ws.Range(strAddress).Copy Sheets("Sheet1").Range("A65536").End(xlUp).Offset(1, 0)
        End If
    Next ws

    Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,183
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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