VBA - copying down a specific cell value ?

Brendan89

New Member
Joined
Oct 18, 2017
Messages
26
I need to add to the code below to also copy the value of cell 'Q3' down into each row each time the macro is enabled.
Sub New_Risk()
Dim varUserInput As Variant
varUserInput = InputBox("Enter Row Number where you want to add a row:", _
"What Row?")
If varUserInput = "" Then Exit Sub
RowNum = varUserInput
ActiveSheet.Unprotect "shearer"
With ActiveCell
Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
Rows(RowNum - 1 & ":" & RowNum - 1).Copy Range("A" & RowNum)
Range(RowNum & ":" & RowNum).SpecialCells(xlCellTypeConstants).ClearContents
End With
Application.CutCopyMode = False
ActiveSheet.Protect "shearer", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
End Sub

Does anyone know if I need to add this to the 'Copy Range' part of this code or somewhere else?

Cheers!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Hi ,

I am not sure whether the code you have posted was doing its job or not ; see if this does what you want :
Code:
Sub New_Risk()
    Dim varUserInput As Variant
    varUserInput = InputBox("Enter Row Number where you want to add a row:", "What Row?")
    If varUserInput = "" Then Exit Sub


    RowNum = varUserInput
    ActiveSheet.Unprotect "shearer"
    With ActiveSheet
         .Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
         .Rows(RowNum - 1 & ":" & RowNum - 1).Copy .Range("A" & RowNum)
         .Range(RowNum & ":" & RowNum).SpecialCells(xlCellTypeConstants).ClearContents
         .Range("Q3").Copy .Range("Q" & RowNum)
    End With


    Application.CutCopyMode = False
    ActiveSheet.Protect "shearer", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
End Sub
 
Upvote 0
Below copies Q3 to the inserted row, adjust to suit:
Code:
Sub New_Risk()
    
    Dim varUserInput As Variant
    
    varUserInput = InputBox("Enter Row Number where you want to add a row:", "What Row?")
    
    If Len(varUserInput) Then

        With ActiveSheet
            .Unprotect "shearer"
            .Cells(varUserInput, 1).Insert shift:=xlDown
            .Cells(varUserInput - 1, 1).EntireRow.Copy .Cells(rownum, 1)
            .Cells(varUserInput, 1).EntireRow.SpecialCells(xlCellTypeConstants).ClearContents
            .Cells(varUserInput, 17).Value = .Cells(3, 17).Value
            Application.CutCopyMode = False
            .Protect "shearer", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
        End With
                
    End If

End Sub
 
Last edited:
Upvote 0
Hi ,

I am not sure whether the code you have posted was doing its job or not ; see if this does what you want :
Code:
Sub New_Risk()
    Dim varUserInput As Variant
    varUserInput = InputBox("Enter Row Number where you want to add a row:", "What Row?")
    If varUserInput = "" Then Exit Sub


    RowNum = varUserInput
    ActiveSheet.Unprotect "shearer"
    With ActiveSheet
         .Rows(RowNum & ":" & RowNum).Insert Shift:=xlDown
         .Rows(RowNum - 1 & ":" & RowNum - 1).Copy .Range("A" & RowNum)
         .Range(RowNum & ":" & RowNum).SpecialCells(xlCellTypeConstants).ClearContents
         .Range("Q3").Copy .Range("Q" & RowNum)
    End With


    Application.CutCopyMode = False
    ActiveSheet.Protect "shearer", AllowFormattingColumns:=True, AllowFormattingRows:=True, AllowFiltering:=True
End Sub

That's done it! Thank you!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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