Excel VBA to paste to new line after entry

Status
Not open for further replies.

jfrancis

New Member
Joined
Nov 7, 2013
Messages
9
I'm trying to make a sales quotation entry process simpler by using macros. This code below works, but it goes horizontally across the sheet instead of going vertically down the columns.

I have dynamic data (from vlookup) generated in cell G3 and I've made a button to copy this data from G3 and paste the value to column A1. As of now, upon clicking the assigned macro button, it pastes data from, G3 to H3, I3, J3, K3 and so on. I need the macro to copy-paste from G3 to the cell directly below, like A1, A2, A3, A4 and so on... :)

Code:
Sub paste2()
' paste2 Macro
    Dim lastCol As Long
' this finds the number of the last column
lastCol = Cells(3, Columns.Count).End(xlToLeft).Column


   Range("G3").Copy


Range("A1").Select
   Cells(3, lastCol + 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Is this what you're after

Code:
Sub paste2()
' paste2 Macro
    Dim lastRow As Long
' this finds the number of the last row
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("G3").Copy
    Cells(lastRow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
 
Last edited:
Upvote 0
Is this what you're after

Code:
Sub paste2()
' paste2 Macro
    Dim lastRow As Long
' this finds the number of the last row
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("G3").Copy
    Cells(lastRow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub

Thank you sericom! This was exactly what I was looking for! Saved me a lot of web searches...
 
Upvote 0
Slightly shorter version without the copy/paste...

Code:
Sub paste2()
    Range("A" & Rows.Count).End(xlUp)(2).Value = Range("G3").Value
End Sub

:biggrin:
 
Last edited:
Upvote 0
Thank you MARK858. I needed the data to be pasted in column D as well and your formula helped me to do that. VB is pretty interesting. I'm currently learning C programming though :)
 
Upvote 0
You're welcome (btw it is not a formula, it is VBA code/script, a formula is what you put in a cell with a =/+ sign at the start :biggrin: or within a code with a .Formula or .FormulaR1C1 and a = in front)
 
Last edited:
Upvote 0
Is this what you're after

Code:
Sub paste2()
' paste2 Macro
    Dim lastRow As Long
' this finds the number of the last row
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Range("G3").Copy
    Cells(lastRow + 1, 1).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
End Sub
hey, could you make it so instead of being the last row, could be an especific row, please!!!
 
Upvote 0

Attachments

  • Capturar.PNG
    Capturar.PNG
    204.1 KB · Views: 76
Upvote 0
Status
Not open for further replies.

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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