What's new

Help Excel VBA Help?

kimmybhoi

Eternal Poster
Established
Joined
Oct 25, 2016
Posts
564
Reaction
375
Points
262
Age
34
I need help in pasting values of cell range to another worksheet's next empty cell/row.

Worksheet names - "data" and "test"

Copy values of B2:B15 from worksheet "data" Paste values to next empty cell in column B of worksheet "test"

This is executed by clicking a button.

I don't use text input box, all I need is just to copy whatever in the cell range into another sheet's next empty cell in specific column.

Thank you for your help.
 
Here's the VBA code that you can use to copy and paste the values of a specific range from one worksheet to another:

Code:
Sub CopyValues()
    Dim dataSheet As Worksheet
    Dim testSheet As Worksheet
    Dim lastRow As Long
    
    ' Set the worksheet objects
    Set dataSheet = ThisWorkbook.Worksheets("data")
    Set testSheet = ThisWorkbook.Worksheets("test")
    
    ' Find the last row in column B of testSheet
    lastRow = testSheet.Cells(Rows.Count, "B").End(xlUp).Row
    
    ' Copy and paste the values
    dataSheet.Range("B2:B15").Copy
    testSheet.Range("B" & lastRow + 1).PasteSpecial xlPasteValues
    
    ' Clear the clipboard
    Application.CutCopyMode = False
End Sub

You can assign this macro to a button to execute it. When you click on the button, it will do the following:

1. Set the worksheet objects for "data" and "test" worksheets
2. Find the last row in column B of "test" worksheet
3. Copy the values from "B2:B15" range of "data" worksheet
4. Paste the values to the next empty cell in column B of "test" worksheet
5. Clear the clipboard

Note that this code only copies and pastes the values, not the formulas or formatting from the source range. If you want to copy the formulas and formatting as well, you can modify the PasteSpecial method accordingly.
 

Similar threads

Back
Top