0

I am trying to add a row to a table and two rows to a second table. Both tables are on the same sheet.

I managed to add cells but the formulas are not updating on that added row. Also, I am unable to add these rows to the bottom of both tables.

Sub Button30_Click()
    Dim varUserInput As Variant, i As Integer
    varUserInput = 32
    rowNum = varUserInput
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
    Rows(rowNum - 1 & ":" & rowNum - 1).Copy Range("A" & rowNum)
    Range(rowNum & ":" & rowNum).ClearContents

    Sheets("SiteForm").Range("A32").Select
    ActiveCell.Formula = "=ROW()-29"
    Sheets("SiteForm").Range("I32").Select
    ActiveCell.Formula = "=J32*H32"
    Sheets("SiteForm").Range("J32").Select
    ActiveCell.Formula = "=(VLOOKUP(B32,Datasheet!$O$3:$Q$23, 2, FALSE))"
    Sheets("SiteForm").Range("K32").Select
    ActiveCell.Formula = "=(VLOOKUP(B32,Datasheet!$O$3:$Q$23, 3, FALSE))"
    Sheets("SiteForm").Range("L32").Select
    ActiveCell.Formula = "=IF(Datasheet!$K$27=TRUE,I32*K32*G32*1.5,I32*K32*G32)"

    Dim rowNumber As Integer, userInputNum As Integer, userInputNum1 As Integer
    On Error Resume Next
    i = Range("J23").Value
    userInputNum = varUserInput + i + 13 - 2
    userInputNum1 = varUserInput + i + 13 - 1

    varUserInput = userInputNum
    rowNum = varUserInput
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
    Rows(rowNum - 1 & ":" & rowNum - 1).Copy Range("A" & rowNum)
    Range(rowNum & ":" & rowNum).ClearContents

    varUserInput = userInputNum1
    rowNum = varUserInput
    Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
    Rows(rowNum - 1 & ":" & rowNum - 1).Copy Range("A" & rowNum)
    Range(rowNum & ":" & rowNum).ClearContents

    Range(Cells(userInputNum, "A"), Cells(userInputNum1, "A")).Merge
    Range(Cells(userInputNum, "B"), Cells(userInputNum1, "C")).Merge
    Range(Cells(userInputNum, "D"), Cells(userInputNum1, "F")).Merge
    Range(Cells(userInputNum, "G"), Cells(userInputNum1, "G")).Merge
    Range(Cells(userInputNum, "L"), Cells(userInputNum1, "L")).Merge

    Sheets("SiteForm").Cells(userInputNum, 2).Select
    ActiveCell.Formula = "=B32"
    Sheets("SiteForm").Cells(userInputNum, 4).Select
    ActiveCell.Formula = "=D32"
    Sheets("SiteForm").Cells(userInputNum, 7).Select
    ActiveCell.Formula = "=H32"

End Sub
Community
  • 1
  • 1

0 Answers0