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

Hello NG,

Can someone please help me with a dynamic last cell problem?
Everyday I have a list of distributors that I have to send pricing info to,
nationwide we have over 35,000 account.
However, if I sort my list by state it come out different everyday.
When I finish sending then pricing info I have to fill in a column with my
name
This column id always D and always starts at D2, D1 is "Contacted By"
I've tried using the macro recorder and it wants to put in actual cell
address, but that change every time.

Sub LastCell()
Dim FirstCell As Variant
Dim LastCell As Variant

Range("A2").Select
FirstCell = ActiveCell.Offset(0, 3).Address
Selection.End(xlDown).Select
LastCell = ActiveCell.Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

End Sub
What I would like to do is fill in column D, from cell "D2" to the last
cell in column with my name - James
Can anyone please help me?
TIA
James


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamic LastCell

Sub LastCell()
Dim FirstCell As String
Dim LastCell As String

FirstCell = Range("A2").Offset(0, 3).Address
LastCell = Range("A2").Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

Names("MyRange").Value = "James"

End Sub


--
Regards,
Tom Ogilvy


"James Agostinho" wrote in message
nk.net...
Hello NG,

Can someone please help me with a dynamic last cell problem?
Everyday I have a list of distributors that I have to send pricing info

to,
nationwide we have over 35,000 account.
However, if I sort my list by state it come out different everyday.
When I finish sending then pricing info I have to fill in a column with my
name
This column id always D and always starts at D2, D1 is "Contacted By"
I've tried using the macro recorder and it wants to put in actual cell
address, but that change every time.

Sub LastCell()
Dim FirstCell As Variant
Dim LastCell As Variant

Range("A2").Select
FirstCell = ActiveCell.Offset(0, 3).Address
Selection.End(xlDown).Select
LastCell = ActiveCell.Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

End Sub
What I would like to do is fill in column D, from cell "D2" to the last
cell in column with my name - James
Can anyone please help me?
TIA
James




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Dynamic LastCell

Let me try that again - several errors/omissions:

Sub LastCell()
Dim FirstCell As String
Dim LastCell As String

FirstCell = Range("A2").Offset(0, 3).Address
LastCell = Range("A2").End(xlDown).Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:= _
"='" & ActiveSheet.Name & "'!" & FirstCell & ":" & LastCell '
Problem is here

Range("MyRange").Value = "James"

End Sub

--
Regards,
Tom Ogilvy


"Tom Ogilvy" wrote in message
...
Sub LastCell()
Dim FirstCell As String
Dim LastCell As String

FirstCell = Range("A2").Offset(0, 3).Address
LastCell = Range("A2").Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersTo:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

Names("MyRange").Value = "James"

End Sub


--
Regards,
Tom Ogilvy


"James Agostinho" wrote in message
nk.net...
Hello NG,

Can someone please help me with a dynamic last cell problem?
Everyday I have a list of distributors that I have to send pricing info

to,
nationwide we have over 35,000 account.
However, if I sort my list by state it come out different everyday.
When I finish sending then pricing info I have to fill in a column with

my
name
This column id always D and always starts at D2, D1 is "Contacted By"
I've tried using the macro recorder and it wants to put in actual cell
address, but that change every time.

Sub LastCell()
Dim FirstCell As Variant
Dim LastCell As Variant

Range("A2").Select
FirstCell = ActiveCell.Offset(0, 3).Address
Selection.End(xlDown).Select
LastCell = ActiveCell.Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

End Sub
What I would like to do is fill in column D, from cell "D2" to the last
cell in column with my name - James
Can anyone please help me?
TIA
James






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Dynamic LastCell

Hi James,

Besides Tom's fix of your code, here are three other ways to do that.

Sub CellNamer()
Dim i As Integer
i = Range("A65000").End(xlUp).Row
Range("B2").Select
For i = 1 To i - 1
ActiveCell.Value = "James"
ActiveCell.Offset(1, 0).Select
Next
End Sub

Sub RangeNamer()
Dim LastRow As Long
Dim Drange As Range
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set Drange = Range("B2:B" & LastRow)
Drange.Value = "James"
End Sub

Sub TheResizeNamer()
Dim i As Integer
i = Cells(Rows.Count, "A").End(xlUp).Row - 1
Range("B2").Resize(i, 1).Value = "James"
End Sub

HTH
Regards,
Howard


"James Agostinho" wrote in message
nk.net...
Hello NG,

Can someone please help me with a dynamic last cell problem?
Everyday I have a list of distributors that I have to send pricing info

to,
nationwide we have over 35,000 account.
However, if I sort my list by state it come out different everyday.
When I finish sending then pricing info I have to fill in a column with my
name
This column id always D and always starts at D2, D1 is "Contacted By"
I've tried using the macro recorder and it wants to put in actual cell
address, but that change every time.

Sub LastCell()
Dim FirstCell As Variant
Dim LastCell As Variant

Range("A2").Select
FirstCell = ActiveCell.Offset(0, 3).Address
Selection.End(xlDown).Select
LastCell = ActiveCell.Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

End Sub
What I would like to do is fill in column D, from cell "D2" to the last
cell in column with my name - James
Can anyone please help me?
TIA
James




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Dynamic LastCell

Gentlemen,
Thank you for the help, I knew there must be way, I played with this for
several hours and I couldn't get the syntax just right.
Anyway thanks
James
"L. Howard Kittle" wrote in message
news:Dr8_b.99725$jk2.468474@attbi_s53...
Hi James,

Besides Tom's fix of your code, here are three other ways to do that.

Sub CellNamer()
Dim i As Integer
i = Range("A65000").End(xlUp).Row
Range("B2").Select
For i = 1 To i - 1
ActiveCell.Value = "James"
ActiveCell.Offset(1, 0).Select
Next
End Sub

Sub RangeNamer()
Dim LastRow As Long
Dim Drange As Range
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Set Drange = Range("B2:B" & LastRow)
Drange.Value = "James"
End Sub

Sub TheResizeNamer()
Dim i As Integer
i = Cells(Rows.Count, "A").End(xlUp).Row - 1
Range("B2").Resize(i, 1).Value = "James"
End Sub

HTH
Regards,
Howard


"James Agostinho" wrote in message
nk.net...
Hello NG,

Can someone please help me with a dynamic last cell problem?
Everyday I have a list of distributors that I have to send pricing info

to,
nationwide we have over 35,000 account.
However, if I sort my list by state it come out different everyday.
When I finish sending then pricing info I have to fill in a column with

my
name
This column id always D and always starts at D2, D1 is "Contacted By"
I've tried using the macro recorder and it wants to put in actual cell
address, but that change every time.

Sub LastCell()
Dim FirstCell As Variant
Dim LastCell As Variant

Range("A2").Select
FirstCell = ActiveCell.Offset(0, 3).Address
Selection.End(xlDown).Select
LastCell = ActiveCell.Offset(0, 3).Address

ActiveWorkbook.Names.Add Name:="MyRange", RefersToR1C1:= _
"=ohio.xls!" & FirstCell & ":" & LastCell ' Problem is here

End Sub
What I would like to do is fill in column D, from cell "D2" to the last
cell in column with my name - James
Can anyone please help me?
TIA
James








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
Dynamic pivot table linked to dynamic excel spreadsheets FErd Excel Worksheet Functions 0 April 29th 10 10:44 PM
Excel 2007 BUG UsedRange/LastCell differences with Excel2003. keepITcool Excel Discussion (Misc queries) 2 May 31st 06 06:18 PM
Help with copying dynamic column selected based on remote cell value and dynamic formula fill ers Charts and Charting in Excel 0 March 1st 06 01:05 AM
Dynamic Range with unused formula messing up x axis on dynamic graph [email protected] Charts and Charting in Excel 2 February 2nd 06 08:02 PM
LastCell Function David Excel Programming 6 December 5th 03 02:51 PM


All times are GMT +1. The time now is 05:34 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"