Hi there,
I´m new in the VBA world and I´m trying to learn how to use it in an efficient way and at the same time develop a feature in my spreadsheet, see bullet 4 below:
#1 Copy an activated row, insert a new row below and paste the formula in column(not formula) there (Solved)
#2 Highlight it with another color (Solved)
#3 Insert a choosen value in column U (via inputbox) ( Solved)
#4 Be able to do this for multiple selected rows(amount of rows varying from time to time). Selection is sometime clustered but sometimes there are other rows in betweeen the selected rows.
This is my code
I´m new in the VBA world and I´m trying to learn how to use it in an efficient way and at the same time develop a feature in my spreadsheet, see bullet 4 below:
#1 Copy an activated row, insert a new row below and paste the formula in column(not formula) there (Solved)
#2 Highlight it with another color (Solved)
#3 Insert a choosen value in column U (via inputbox) ( Solved)
#4 Be able to do this for multiple selected rows(amount of rows varying from time to time). Selection is sometime clustered but sometimes there are other rows in betweeen the selected rows.
This is my code
Code:
Private Sub CommandButton9_Click()
' add_row_62 Macro
'
Dim rng As Range
Set rng = Activecell.Range("A1") ' <~~ Change this
lRsp = MsgBox("Add row below this row " & lRow & " and fill in code 62?", _
vbQuestion + vbYesNo, "Kritiskt moment")
If lRsp <> vbYes Then Exit Sub
' Insert a row below the current one
rng.Offset(1).Insert
' Copy the current row and paste it into the row we just inserted
rng.EntireRow.Copy rng.Offset(0)
rng.Offset(0).EntireRow.Copy
rng.Offset(1).PasteSpecial xlPasteFormulas
rng.Offset(0).Copy
rng.Offset(1).PasteSpecial xlPasteValues
Set rng = rng.Offset(1)
Activecell.Range("A1:W1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
Selection.End(xlToLeft).Select
Activecell.Offset(0, 22).Range("A1").Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorAccent2
.TintAndShade = 0.399975585192419
.PatternTintAndShade = 0
End With
Activecell.Offset(0, 0).Range("A1").Select
Activecell.FormulaR1C1 = "OB"
Activecell.Offset(0, -5).Range("A1").Select
Activecell.FormulaR1C1 = "62"
Activecell.Offset(0, 3).Range("A1").Select
Selection.ClearContents
Me.Hide
QTYInput = InputBox("Hours to be filled")
Activecell.Value = QTYInput
Activecell.Select
With Selection
.NumberFormat = "General"
.Value = .Value
'
End With
End Sub