How to create an Input Box with functions

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
184
Office Version
  1. 365
Platform
  1. Windows
I am not sure where to be on creating vba. The workbook has 7 tabs labeled; 9459, 8616, 7471, 0129, 8848, 5649. Each tab (worksheet) needs the name of the tab put in col H (A-G has information). So for tab "9459" I need the number 9459 copied in to every row in col H. I need to do this for each tab.
Next step is to consolidate all seven tabs in to one master tab then a pivot table is created.
I was thinking of setting up an input box for the end user to enter the numbers "9459"...and then the vba would go to that tab do the process. When the user is finished enter each number listed then the input box would finish and the second step would take place.

I have never created input box to do a function. Usually I would create a new tab with control form buttons for the user to go and press for each action above.

What is your advice? I created the code below for the first tab but I can not get the A2 cell to copy down to the last row in col B. Also is there a better way to write this for a total of 7 tabs?

VBA Code:
Dim ws As Worksheet
'Set ws = ActiveSheet
For Each ws In ActiveWindow.SelectedSheets
'MsgBox ws.name
Next ws
     Dim LastRow As Long
    LastRow = Cells(Rows.Count, 2).End(xlUp).Row
    
Application.ScreenUpdating = False
    Sheets("9459").Select
    Columns("A:A").Select
    Selection.Insert Shift:=xlToRight
    Selection.NumberFormat = "0"
    Range("A1").Select
    ActiveCell.FormulaR1C1 = "Rpt No,"
    
    Range("A2").Select
    ActiveCell.FormulaR1C1 = "9459"
    Range("A2").Select
    Selection.Copy
    ActiveSheet.Paste
    Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Value = "9459"
    Application.CutCopyMode = False '
 

Some videos you may like

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,143
Baby Steps

this code will add the sheet names to the cells in column H

VBA Code:
Sub add_Names()

For Each ws In Sheets
lr = ws.Cells(Rows.Count, "A").End(xlUp).Row
ws.Range("H1:H" & lr) = ws.Name
Next ws

End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,122,246
Messages
5,595,044
Members
413,963
Latest member
teggl97

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
Top