Trying to add an Inputbox in Macro

Vikas Kumar

New Member
Joined
Apr 2, 2017
Messages
49
Dear Experts,

I have following macro which split a mastersheet into multiple sheet based on its city,


Sub DataSplit_2()
Dim City As String
Dim Lr As Byte
Range("C2").Activate
Do While ActiveCell.Value <> ""
City = ActiveCell.Value
On Error Resume Next
If Sheets(City) Is Nothing Then
On Error GoTo 0
Range("A1").EntireRow.Copy
Sheets.Add
Range("A1").PasteSpecial
ActiveSheet.Name = City
Sheets("Data").Activate
ActiveCell.EntireRow.Copy
Sheets(City).Activate
ActiveCell.Offset(1, 0).PasteSpecial
Sheets("Data").Activate
Else
ActiveCell.EntireRow.Copy
Sheets(City).Activate
Lr = Range("A" & Rows.Count).End(xlUp).Row + 1
Range("A" & Lr).PasteSpecial
Sheets("Data").Activate
End If
ActiveCell.Offset(1, 0).Activate
Loop
End Sub

What im looking now, To just add a inputbox into the code so that whenever i run macro firstly it ask to 'Enter your city name for which you want to splil' and whichever city enters only for those a new worksheet (single) to be created.

One more thing - I do not want to split "Ahmedabad & Mumbai" city so whenever I enter anyone among of them a msgbox should appear stating "You can't split this sheet".

Hope you won't be confuse by above statement.

Also for ease pasting my data's Header,


[TABLE="width: 582"]
<tbody>[TR]
[TD="class: xl63, width: 82"]Zone[/TD]
[TD="class: xl63, width: 82"]Region[/TD]
[TD="class: xl63, width: 98"]City[/TD]
[TD="class: xl63, width: 99"]Product[/TD]
[TD="class: xl63, width: 70"]Qty[/TD]
[TD="class: xl63, width: 72"]Price[/TD]
[TD="class: xl63, width: 79"]Sale (in Rs.)[/TD]
[/TR]
</tbody>[/TABLE]

Any help would be appreciated. Thank in Advance.
 
Hi Dave,

This one is doing much better but post splitting the input city, Just copy headers only does not take rest data of entered city.


Check your spelling when entering in InputBox.

Dave
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Randomly tested with multiple cities. Pls have a check with yourself also.


Works ok for me - Input is case sensitive

Change the line shown in RED & see if helps

Rich (BB code):
For Each Cell In RNG
        If UCase(Cell.Value) = UCase(City) Then

Dave
 
Last edited:
Upvote 0
Works ok for me - Input is case sensitive

Change the line shown in RED & see if helps

Rich (BB code):
For Each Cell In RNG
        If UCase(Cell.Value) = UCase(City) Then

Dave


This was the expected bro........Thanks a ton for help.

Really laudable☺.
 
Upvote 0

Forum statistics

Threads
1,223,892
Messages
6,175,236
Members
452,621
Latest member
Laura_PinksBTHFT

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