Pineapple_Crazy
Board Regular
- Joined
- May 2, 2017
- Messages
- 51
Hey Guys,
Been having some issues with the piece of code below. Basically I am copying over 1 value from a source sheet into another workbook by using the criteria depicted in the code below. However, about 70% of the time I receive the error of "The Action won't work on multiple selections". I am only selecting, copying, and pasting a single value though and cannot figure out why the code fails with this error. The code fails where it is highlighted below and in bigger font. I've done some research and haven't found a great solution. Anyone have a work around for this or experienced something similar? Thanks in advance!
Been having some issues with the piece of code below. Basically I am copying over 1 value from a source sheet into another workbook by using the criteria depicted in the code below. However, about 70% of the time I receive the error of "The Action won't work on multiple selections". I am only selecting, copying, and pasting a single value though and cannot figure out why the code fails with this error. The code fails where it is highlighted below and in bigger font. I've done some research and haven't found a great solution. Anyone have a work around for this or experienced something similar? Thanks in advance!
Code:
Sub FindingValuesTest()
'Declaring variables
Dim FindRow As Long, findrow2 As Long
Dim find As Range
Dim StrFile As String
Dim StrPath As String
Dim r1 As Long, wb As Workbook
'location of source file
StrPath = "Y:\Finance\BI\Pete\Pete Documents\Misc\"
StrFile = Dir(StrPath & "Vendor*" & "*.xls*")
'msg box to enter vendor ID
myValue = InputBox("Please Enter the Vendor Name", "VENDOR NAME", "REDH001")
'Opens file
Set wb = Workbooks.Open(Filename:=StrPath & StrFile)
wb.Activate
'Finding a match
FindRow = Range("A:A").find(myValue, Range("A1")).Row
r1 = FindRow
Do
wb.Activate
On Error Resume Next
FindRow = Range("A:A").find(what:=myValue, after:=Cells(FindRow, 1)).Row
findrow2 = Range("H:H").find(what:="Modified:", after:=Range("H" & FindRow)).Row
Set rgCopy = Range("H" & FindRow + 10 & ":H" & findrow2 + 0).Offset(0, 3).SpecialCells(xlCellTypeConstants)
On Error GoTo 0
If Not rgCopy Is Nothing Then
[SIZE=5][B] rgCopy.Copy[/B][/SIZE]
'Shifts focus back to macro workbook and pastes data in given worksheet. Puts cursor at bottom of A (5000) and searches up for last data entered.
Windows("FinalReport_Vendor.xlsm").Activate
Sheets("Data").Activate
ActiveSheet.Range("AC5000").End(xlUp).Offset(1, 0).Select
'ActiveSheet.Paste
Selection.PasteSpecial paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=True, Transpose:=True
Set rgCopy = Nothing
End If
Loop While FindRow > 1 And FindRow <> r1
End Sub