How to create an Input Box with functions

fvisions

Board Regular
Joined
Jul 29, 2008
Messages
182
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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

rpaulson

Well-known Member
Joined
Oct 4, 2007
Messages
1,135
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,118,886
Messages
5,574,836
Members
412,620
Latest member
sharma7s
Top