VBA not Capturing all Formulas / Data Validation for Copy/Paste

davidanaya11579

New Member
Joined
Dec 26, 2017
Messages
11
Hello Geniuses! I am creating a form and trying to make it as user friendly as possible, creating command buttons that will automatically copy all formulas and data validations from the current line, and insert them in the desired row (same sheet). For some reason, this isn’t copying my formulas, just the data validations?? Below is what I have so far:

Private Sub CommandButton2_Click()

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
Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
Rows(rowNum - 1 & ":" & rowNum - 1).Copy Range("A" & rowNum)
Range(rowNum & ":" & rowNum).ClearContents

End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Hi & welcome to the board.
You are copying to row rowNum & then clearing the contents. Hence you lose the formulae
 
Upvote 0
If anyone has any better ideas on how to copy and paste all formulas and data validation and paste into the very next row of the same sheet. The below is what I have, but it is not capturing the formulas, only the data validation.

Private Sub CommandButton2_Click()
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
Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
Rows(rowNum - 1 & ":" & rowNum - 1).Copy Range("A" & rowNum)

End Sub
 
Upvote 0
Are there any formulae in the row above the inserted row?
 
Upvote 0
Actually I think I figured out the issue, I just don't know what the solution is. The cell which is not copying is simply pulling a value from another cell further up in the form, it is not pulling that referenced cell value. I would also be okay if the new line simply copied the value rather than the referenced cell (I'm hoping that makes sense). Here's an example: The line being copied has 2 data validations in A25 & B25, F25 is simply pulling the value from D18, which is constant. Is there a way for the new line to reference D18, or the pulled value that appears in F25?
 
Upvote 0
Add this to the end of your code
Code:
Range("F" & rownum).Value = Range("D18").Value
 
Upvote 0

Forum statistics

Threads
1,223,907
Messages
6,175,300
Members
452,633
Latest member
DougMo

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