Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Relative Reference and AutoFill- Macro

I need to copy a formula in a new column for each row. When recording the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the autofill to
adapt. The following is part of the script I think needs adjustment I just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Relative Reference and AutoFill- Macro

dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the autofill to
adapt. The following is part of the script I think needs adjustment I just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Relative Reference and AutoFill- Macro

Missing a space:

Range("H2").AutoFill Destination:=Range("H2:H" & endrow)

--

Vasant


"Rowan" wrote in message
...
dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording

the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the

autofill to
adapt. The following is part of the script I think needs adjustment I

just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Relative Reference and AutoFill- Macro

I also didn't type Cells with a capital C, leave a space between the , and 7
or use a capital U in xlUp etc etc but that is the wonderfull thing about the
VBE: it'll do all of that for me. <g

"Vasant Nanavati" wrote:

Missing a space:

Range("H2").AutoFill Destination:=Range("H2:H" & endrow)

--

Vasant


"Rowan" wrote in message
...
dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording

the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the

autofill to
adapt. The following is part of the script I think needs adjustment I

just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 83
Default Relative Reference and AutoFill- Macro

I deliberately use a capital letter in my variable names and leave out spaces
and when I move to next line if VB doesnt correct proper case and space I
know I have a error.
--
Jim at Eagle


"Rowan" wrote:

I also didn't type Cells with a capital C, leave a space between the , and 7
or use a capital U in xlUp etc etc but that is the wonderfull thing about the
VBE: it'll do all of that for me. <g

"Vasant Nanavati" wrote:

Missing a space:

Range("H2").AutoFill Destination:=Range("H2:H" & endrow)

--

Vasant


"Rowan" wrote in message
...
dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording

the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the

autofill to
adapt. The following is part of the script I think needs adjustment I

just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default Relative Reference and AutoFill- Macro

Hi Rowan

Your code is really useful. However i have a similar situation but the
starting cell to copy down using autofill might not be H2, might be H3, H5,
H100.

Can I use the actively selected cell to perform the autofill down? let say
it is in the H column?

Thanks you very much!

Leung


"Rowan" wrote:

dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the autofill to
adapt. The following is part of the script I think needs adjustment I just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Relative Reference and AutoFill- Macro

dim endRow as long
endRow = cells(rows.count,ActiveCell.Column).end(xlup).row
ActiveCell.AutoFill
Destination:=Range(Activecell,Cells(endrow,ActiveC ell.Column))

or
dim EndCell as Range
set EndCell = cells(rows.count,ActiveCell.Column).End(xlup)
ActiveCell.AutoFill Destination:=Range(ActiveCell,EndCell)


--
Regards,
Tom Ogilvy

"Leung" wrote in message
...
Hi Rowan

Your code is really useful. However i have a similar situation but the
starting cell to copy down using autofill might not be H2, might be H3,

H5,
H100.

Can I use the actively selected cell to perform the autofill down? let say
it is in the H column?

Thanks you very much!

Leung


"Rowan" wrote:

dim endRow as long
endRow = cells(rows.count,7).end(xlup).row
Range("H2").AutoFill Destination:=Range("H2:H" &endrow)

should give your the required result.

Regards
Rowan


"Andy Roberts" wrote:

I need to copy a formula in a new column for each row. When recording

the
macro I am using the autofill function however each time I use this
spreadsheet there will be a different number of rows. I need the

autofill to
adapt. The following is part of the script I think needs adjustment I

just
don't know how to adjust it. Thanks in advance for any ideas.

Range("H2").Select
Selection.AutoFill Destination:=Range("H2:H423")
Range("H2:H423").Select



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
Relative reference? in macro TRYING Excel Worksheet Functions 3 November 20th 07 12:00 AM
Using relative reference in macro Bas Excel Discussion (Misc queries) 0 March 23rd 06 12:11 PM
Relative reference autofill increment other than +1 SteveB Excel Discussion (Misc queries) 3 June 14th 05 07:40 PM
Relative reference in macro Ricki Miles Excel Programming 3 January 23rd 05 08:51 PM
Relative Reference in a Macro DRH Excel Programming 2 December 31st 04 02:20 PM


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

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

About Us

"It's about Microsoft Excel"