Copy/Paste based on Condition from a Data Validation List

k10riley

New Member
Joined
Dec 1, 2021
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hello!

I have the following code that copies a series of cells and transposes and paste the cells in another sheet in the workbook from a data validation list. The data validation list cell is located on the "Analysis" tab. The code runs through the list and pulls the corresponding data from cells C10:G10 and pastes the information into the "Replication Results" tab. My issue is the data validation list has a different selection of data as a result of each item in the list (specifically two lengths). The data validation list information referring to "Apple" needs to copy and paste cells C10:G10, where "Orange" should only paste C:10:F10.

I know I need to create a condition within my code, but I'm not sure where to input this? I've tried several things but so far I've been unsuccessful. Here's the original code.
VBA Code:
Sub SpitValues()
Dim dvCell As Range
Dim inputRange As Range
Dim c As Range
Dim i As Long
Dim h As Long
Dim RNG1 As Range, RNG2 As Range

'Set the cell that contains the data validation list
Set dvCell = Worksheets("Analysis").Range("C2")
'Determine where validation comes from
Set inputRange = Evaluate(dvCell.Validation.Formula1)
   
i = 3
h = 10

'Begin our loop
Application.ScreenUpdating = False
For Each c In inputRange
    dvCell = c.Value
    
 Set RNG1 = Worksheets("Analysis").Range("C10:G10")
 Set RNG2 = Worksheets("Replication Results").Cells(i, "D")

 RNG1.Copy
 RNG2.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=True
 RNG2.Style = "Percent"
 RNG2.NumberFormat = "0.000%"

 i = i + 5
 
Next c

Application.ScreenUpdating = True
End Sub

Thank you for your insight!
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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