VBA to copy range to bottom of existing table

keef2

Board Regular
Joined
Jun 30, 2022
Messages
185
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am hoping someone can help me with VBA code. Looking to copy the format and formulas from range A3:J8 and paste below the bottom of the list which in this case would be starting Row 45. I also am hoping to have a dialog box that the user inputs how many projects to add. For example this would allow user to input 1 or input x num and add the range or x num ranges to bottom of table. Any help would be much appreciated. My current VBA code is not doing what I was hoping. Any help is much appreciated. Thanks in advance!

Here is the workbook:
Thursday KEM WORKING.xlsx
ABCDEFGHIJ
1
2Day of Week:FridayJob/LocationDate:9/2/2022
3Job #:3389Job Name:Kanebridge Expansion Time:7:00
4Location:1125 Gateway Drive, Elgin, IL 60123
5Employees :
6
7
8
9Job #:3388Job Name:Schaumburg Honda Time:7:00
10Location:1100 E. Golf Rd. Schaumburg, IL 60173
11Employees :
12
13
14
15Job #:Job Name: Time:7:00
16Location: 
17Employees :
18
19
20
21Job #:Job Name: Time:7:00
22Location: 
23Employees :
24
25
26
27Job #:Job Name: Time:7:00
28Location: 
29Employees :
30
31
32
33Job #:Job Name: Time:7:00
34Location: 
35Employees :
36
37
38
39Job #:Job Name: Time:7:00
40Location: 
41Employees :
42
43
44
Schedule
Cell Formulas
RangeFormula
C2C2=TEXT(I2,"dddd")
I2I2=TODAY()
E3,E39,E33,E27,E21,E15,E9E3=IFERROR(VLOOKUP(B3,Table2,2,FALSE),"")
E4,E40,E34,E28,E22,E16,E10E4=IFERROR(VLOOKUP(B3,Table2,3,FALSE),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E39Expression=COUNTIF($C39,"*Job*")textNO
E33Expression=COUNTIF($C33,"*Job*")textNO
E27Expression=COUNTIF($C27,"*Job*")textNO
E21Expression=COUNTIF($C21,"*Job*")textNO
E15Expression=COUNTIF($C15,"*Job*")textNO
C39:D39,F39:H39Expression=COUNTIF($C39,"*Job*")textNO
C33:D33,F33:H33Expression=COUNTIF($C33,"*Job*")textNO
C27:D27,F27:H27Expression=COUNTIF($C27,"*Job*")textNO
C21:D21,F21:H21Expression=COUNTIF($C21,"*Job*")textNO
C15:D15,F15:H15Expression=COUNTIF($C15,"*Job*")textNO
C3:H3,C9:H9Expression=COUNTIF($C3,"*Job*")textNO


Here is my current VBA code:
VBA Code:
Sub AddInputRow()
    subName = "AddInputRow" 'For Error handling only

    On Error GoTo Nope

    'Get active sheet
    Dim act As Worksheet
    Set act = ThisWorkbook.ActiveSheet

    'prompt for user entry and loop back if invalid
    StrPrompt = "Enter number of Jobs to insert:"

Redo:
    xNum = Application.InputBox(StrPrompt, "Insert Rows at Bottom", , , , , , Type:=1)
    If xNum = 0 Or xNum = "" Or xNum = vbNullString Then
        'User Cancelled and close box
    ElseIf xNum < 1 Or Int(xNum) / xNum <> 1 Then
        'User entered a non-positive integer
        GoTo Redo
    Else
    
    'Add rows Main Table & Sales Table and update formatting and formulas
    bot_row = act.Range("AZ1")
    act.Rows(bot_row & ":" & bot_row + (xNum - 1)).Insert Shift:=x1ShiftDown
    act.Range("A3" & bot_row - 1 & ":J8" & bot_row - 1).Copy act.Range("A3" & bot_row & ":J8" & bot_row + (xNum - 1))
    Application.CutCopyMode = False
 
End If

Continue:
    'Calculate everything once when finished and enable events
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    Application.ScreenUpdating = True
    Exit Sub
    
'Do this if error occurs
Nope:
    MsgBox "An error has been logged: " & vbNewLine & ThisWorkbook.ActiveSheet.Name & vbNewLine & subName & "(Line " & Erl & ")" & vbNewLine & Err.Description
    Resume Continue
    
End Sub
 

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

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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