ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA code need help on CopyPaste (https://www.excelbanter.com/excel-programming/285616-vba-code-need-help-copypaste.html)

alienscript

VBA code need help on CopyPaste
 
I have a list of PartNumber ranging from B2:B6880 and I am vlooking them
up to other worksheets for values of Safety-Stock, Qty-on-hand, PO-Qty,
etc..

For example, I insert column N to vlookup for the Safety-Stock values.
Double-clicking the black cross-sign that appears on the bottom-right
of cell N2 Vlookup formula doesn't copy the N2 formula to N6880 because
there are some blank cells in column M and column O.

I am hoping someone can help me with a code which can allow to copy
cell N2 formula to the last cell in column N where the whole row is not
totally blank, ie. at least has a cell in the row populated with
value.
Eg, if this row as mentioned above is row 6880, then row 6881 onwards
will be totally blank.


Appreciate so much if someone can help with with a code to do this.
Thanks so much in advance!


---
Message posted from http://www.ExcelForum.com/


Vasant Nanavati

VBA code need help on CopyPaste
 
The simple solution would be to drag the formula down. However, if you want
a macro solution:

Sub CopyToEnd() 'untested
Dim LastRow As Long
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
Range("N2").Copy Range("N3:N" & LastRow)
End Sub

--

Vasant

"alienscript" wrote in message
...
I have a list of PartNumber ranging from B2:B6880 and I am vlooking them
up to other worksheets for values of Safety-Stock, Qty-on-hand, PO-Qty,
etc..

For example, I insert column N to vlookup for the Safety-Stock values.
Double-clicking the black cross-sign that appears on the bottom-right
of cell N2 Vlookup formula doesn't copy the N2 formula to N6880 because
there are some blank cells in column M and column O.

I am hoping someone can help me with a code which can allow to copy
cell N2 formula to the last cell in column N where the whole row is not
totally blank, ie. at least has a cell in the row populated with
value.
Eg, if this row as mentioned above is row 6880, then row 6881 onwards
will be totally blank.


Appreciate so much if someone can help with with a code to do this.
Thanks so much in advance!


---
Message posted from http://www.ExcelForum.com/




alienscript[_2_]

VBA code need help on CopyPaste
 
Hi Vasant,

Thanks for your help.

What if in stead of selecting this:

Range("N2").Copy Range("N3:N" & LastRow)

I want to randomly select any cells in row 2 to CopyToEnd, how can I
use the Selection in ActiveSheet to do this job ?

Thanks in advance for help.


---
Message posted from http://www.ExcelForum.com/


Colo[_40_]

VBA code need help on CopyPaste
 
Hi alienscript


Code:
--------------------


Dim col As Long
col = ActiveCell.Column
Range(Cells(2, col), Cells(Rows.Count, col).End(xlUp)).Formula = _
Cells(2, col).Formula


--------------------



---
Message posted from http://www.ExcelForum.com/


alienscript[_3_]

VBA code need help on CopyPaste
 
Hi Colo,

I placed my cursor at Cell M2 that has a formula and run the code belo
but it doesn't copy down the formula !

Is there something missing from your code ?
Hope you can help. Thanks.


Sub Cell2CopyToEnd()

Dim col As Long
col = ActiveCell.column
Range(Cells(2, col), Cells(Rows.Count, col).End(xlUp)).Formula = _
Cells(2, col).Formula

End Su

--
Message posted from http://www.ExcelForum.com


Colo[_47_]

VBA code need help on CopyPaste
 
Hi

Let me know one thing pls. how can i know the last row.? I mean which
column should be based for getting the last row?


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 03:42 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com