Reputation: 183
I have two worksheets I am working with.
Once called Data other 2018-2019
I want to paste the value from cell m22 (data) into row 3 (2018-2019) if the value in row 2 (2018-2019) is equal to that in cell m1 (data).
how do i do this?
Upvotes: 0
Views: 56
Reputation: 1542
Try:
Public Sub PasteBasedOnValue()
Dim wb As Workbook
Set wb = ActiveWorkbook
Dim source As Worksheet
Set source = wb.Sheets("Data")
Dim dest As Worksheet
Set dest = wb.Sheets("2018-2019")
Dim valueToLookFor
valueToLookFor = source.Range("M1")
Dim valueToPaste
valueToPaste = source.Range("M22")
Dim rowToSearch As Integer
rowToSearch = 2
Dim rowToPaste As Integer
rowToPaste = 3
Dim maxCols As Integer
maxCols = 256
Dim c As Integer
c = 1
Do While c <= maxCols
If dest.Cells(rowToSearch, c) = valueToLookFor Then
dest.Cells(rowToPaste, c) = valueToPaste
Exit Do
End If
c = c + 1
Loop
End Sub
I'm interpreting your spreadsheet as looking like this screen capture below. Based on your response, that's not exactly what it's like. So if you could paste a screen capture of the real spreadsheet, I could modify my code accordingly.
Upvotes: 1