Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Autofill Question

I would like to use the autofill function but am not sure the best way to
start. I have a spreadsheet that will vary on the number of columns of data
and rows. I want to find the first blank column, select the second row
(first row I will place a header) place a formula in the second row and
autofill to the last row of data.

Assume current sheet has columns A:E
Assume 100 rows of data
Assume formula to autofill in column is A2*C2

Hopefully this makes sense,

Thanks,

SJ
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Autofill Question

Dim lastrow as Long, lastcol as Long
lastrow = cells(rows.count,1).End(xlup).Row
lastcol = cells(1,columns.count).End(xlToLeft).Column

cells(2, lastcol + 1).Resize(lastrow-1, 1).Formula = "=A2*C2"

--
regards,
Tom Ogilvy


"Scott J" wrote:

I would like to use the autofill function but am not sure the best way to
start. I have a spreadsheet that will vary on the number of columns of data
and rows. I want to find the first blank column, select the second row
(first row I will place a header) place a formula in the second row and
autofill to the last row of data.

Assume current sheet has columns A:E
Assume 100 rows of data
Assume formula to autofill in column is A2*C2

Hopefully this makes sense,

Thanks,

SJ

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Autofill Question

Tom,

Thanks for getting back to me. This works perfectly.

Thanks for the help, I really appreciate it.

Scott J

"Tom Ogilvy" wrote:

Dim lastrow as Long, lastcol as Long
lastrow = cells(rows.count,1).End(xlup).Row
lastcol = cells(1,columns.count).End(xlToLeft).Column

cells(2, lastcol + 1).Resize(lastrow-1, 1).Formula = "=A2*C2"

--
regards,
Tom Ogilvy


"Scott J" wrote:

I would like to use the autofill function but am not sure the best way to
start. I have a spreadsheet that will vary on the number of columns of data
and rows. I want to find the first blank column, select the second row
(first row I will place a header) place a formula in the second row and
autofill to the last row of data.

Assume current sheet has columns A:E
Assume 100 rows of data
Assume formula to autofill in column is A2*C2

Hopefully this makes sense,

Thanks,

SJ

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Autofill Question

Since you're putting headers in row 1, can you use row 1 to determine the next
available column?

And can you pick out a column that can be used to determine the last used row.

I used row 1 and column A in the following:

dim LastRow as long
dim NextCol as long
dim wks as worksheet

set wks = worksheets("sheet999")

with wks
NextCol = .cells(1,.columns.count).end(xltoleft).column + 1
lastrow = .cells(.rows.count,"A").end(xlup).row

.range(.cells(2,nextcol),.cells(lastrow,nextcol)). formula _
= "=a2*c2"
end with

(untested, uncompiled. Watch for typos.)

Scott J wrote:

I would like to use the autofill function but am not sure the best way to
start. I have a spreadsheet that will vary on the number of columns of data
and rows. I want to find the first blank column, select the second row
(first row I will place a header) place a formula in the second row and
autofill to the last row of data.

Assume current sheet has columns A:E
Assume 100 rows of data
Assume formula to autofill in column is A2*C2

Hopefully this makes sense,

Thanks,

SJ


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 17
Default Autofill Question

Dave,

Thanks for getting back to me. Your code works perfectly just the way you
have it. Thanks for the help, I really do appreciate it. Both you and Tom
are awesome at coding. I am a beginner and am continually learning. It is
amazing the number of ways you can get the desired result with a slightly
different approach.

I have browsed through alot of the responses on the boards and I think you
guys are the most consistent and best out there.

Thanks again,

Scott J

"Dave Peterson" wrote:

Since you're putting headers in row 1, can you use row 1 to determine the next
available column?

And can you pick out a column that can be used to determine the last used row.

I used row 1 and column A in the following:

dim LastRow as long
dim NextCol as long
dim wks as worksheet

set wks = worksheets("sheet999")

with wks
NextCol = .cells(1,.columns.count).end(xltoleft).column + 1
lastrow = .cells(.rows.count,"A").end(xlup).row

.range(.cells(2,nextcol),.cells(lastrow,nextcol)). formula _
= "=a2*c2"
end with

(untested, uncompiled. Watch for typos.)

Scott J wrote:

I would like to use the autofill function but am not sure the best way to
start. I have a spreadsheet that will vary on the number of columns of data
and rows. I want to find the first blank column, select the second row
(first row I will place a header) place a formula in the second row and
autofill to the last row of data.

Assume current sheet has columns A:E
Assume 100 rows of data
Assume formula to autofill in column is A2*C2

Hopefully this makes sense,

Thanks,

SJ


--

Dave Peterson



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofill Question James8309 Excel Worksheet Functions 1 August 24th 08 11:03 AM
Autofill in VBA question CarlosAntenna Excel Programming 4 April 12th 07 08:48 PM
Autofill question lob Excel Worksheet Functions 2 February 17th 05 04:07 PM
Q. Autofill question: Can I autofill alpha characters like I can numbers? George[_22_] Excel Programming 5 August 7th 04 10:33 AM
Autofill question Eric Dreshfield Excel Programming 3 September 3rd 03 02:10 PM


All times are GMT +1. The time now is 03:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"