Need help

wroze27

New Member
Joined
Apr 23, 2021
Messages
31
Office Version
  1. 2019
Platform
  1. Windows
I need a code so that it reads a certain cell ( Cell A2 in this case) and if it matches the right name ( a in this example) it will copy specific cells and paste them into the last line in a column. Currently I cannot get it to paste. Are my notations incorrect and can somebody help me get this working? Thanks so much guys.


VBA Code:
Sub Test()
    Dim N As Long
    N = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 1
If Sheet1.Range("A2") = a Then
    Sheet2.Cells(N, A) = Sheet1.Range("B2")
    Sheet2.Cells(N, A) = Sheet1.Range("C2")
    End If
Else
End If
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Just to be clear, when I say paste in the last cell in a column, I mean that I want it to paste in the empty cell just below the last cell with info in it
 
Upvote 0
Do you want the two values underneath each other in col A or in cols A & B?
 
Upvote 0
Do you want the two values underneath each other in col A or in cols A & B?
I want to be able to paste the two values beside each other but both would be in the last row in their column
 
Upvote 0
In that case how about
VBA Code:
Sub Test()
    Dim N As Long
    N = Sheet2.Cells(Rows.Count, "A").End(xlUp).Row + 1
If Sheet1.Range("A2") = "a" Then
    Sheet2.Cells(N, "A") = Sheet1.Range("B2")
    Sheet2.Cells(N, "B") = Sheet1.Range("C2")
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,549
Members
449,089
Latest member
davidcom

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