ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Record Macro in Excel, run macro untill last column (https://www.excelbanter.com/excel-programming/414764-record-macro-excel-run-macro-untill-last-column.html)

Oamya Kim

Record Macro in Excel, run macro untill last column
 
Hi,
I want to record macro to perform some functions (e.g., simple funtion as
below).
I'd like to hv result shown in column B according to input data from col A,
but the below macro only run up to certain number of rows (here is 4 rows)
only.

How about If I input data at column A up to 100 rows, or sometimes 5000 rows,

Pls anyone help me, which additional VBA code i should add ii order to run
the macro up to numbers of rows at each time.

col A col B
Items Test
BHAKSJDDKF =left(A2,5)
BHEKJFKJG
BHM5FGF
BHPKRG


Sub AddPrefix()

Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],5)"
Range("B2:B5").Select
Selection.FillDown
End Sub

Pls. help. Thanks a lot

Wigi

Record Macro in Excel, run macro untill last column
 
Sub AddPrefix()

Range("B2:B" & Range("A" & Rows.Count).End(xlUp).Row).Formula =
"=LEFT(RC[-1],5)"
End Sub


--
Wigi
http://www.wimgielis.be = Excel/VBA, soccer and music


"Oamya Kim" wrote:

Hi,
I want to record macro to perform some functions (e.g., simple funtion as
below).
I'd like to hv result shown in column B according to input data from col A,
but the below macro only run up to certain number of rows (here is 4 rows)
only.

How about If I input data at column A up to 100 rows, or sometimes 5000 rows,

Pls anyone help me, which additional VBA code i should add ii order to run
the macro up to numbers of rows at each time.

col A col B
Items Test
BHAKSJDDKF =left(A2,5)
BHEKJFKJG
BHM5FGF
BHPKRG


Sub AddPrefix()

Range("B2").Select
ActiveCell.FormulaR1C1 = "=LEFT(RC[-1],5)"
Range("B2:B5").Select
Selection.FillDown
End Sub

Pls. help. Thanks a lot



All times are GMT +1. The time now is 08:02 PM.

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