PDA

View Full Version : Solved: paste file name in all rows of a column



mikeo1313
08-17-2010, 03:18 PM
I'd like to paste in all rows of a column the name of the speadsheet file.

for example. spreadsheet file = apples.xlsx

column C
apples
apples
apples
apples
apples
..
..
..


Seems pretty simple but I intend on running a macro on a folder of files, besides running some other formatting this will finish things up and save me having to go in the files one by one.

mikeo1313
08-17-2010, 04:56 PM
this will supposedly get the name of the workbook


ThisWorkbook.Name


this will get the max amount of rows used

ActiveSheet.UsedRange.Rows.Count


Ok, this is how far I got



sub filename2row()

dim filename as string
dim rowsused as integer
filename = ThisWorkbook.Name
rowsused = activesheet.usedrange.rows.count

?

end sub

Blade Hunter
08-17-2010, 05:03 PM
One line does it:


Range("C:C").Formula = activeworkbook.Name

mikeo1313
08-17-2010, 05:19 PM
worked great!