Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Variable Names Range - Help Needed

Hi all,

I am using the code below to try and resize the range in case a record has
been added to the bottom of this range. I am not sure if the "Old" range must
first be deleted before adding it again. I get a "Run-Time error '13': Type
mismatch" message when i run it at the point mentioned below.

Any help much appreciated.


Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

'Application.Workbooks(wb).Names("Part_Family_Desc ription").Delete<= ??

'<<== ERROR MESSAGE AT THIS POINT ======
Workbooks(wb).Names.Add Name:="Part_Family_Description", _
RefersTo:=Workbooks(wb).Sheets("sh").Range("D3",
Range("D65536").End(xlUp))

cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub

--
Les
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Variable Names Range - Help Needed

Les,

Maybe this

Dim rng As Range
Set rng = Range("Part_Family_Description")
lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
added = lastrow - rng.Rows.Count
rng.Resize(rng.Rows.Count + added).Name = "Part_Family_Description"

Mike

"Les" wrote:

Hi all,

I am using the code below to try and resize the range in case a record has
been added to the bottom of this range. I am not sure if the "Old" range must
first be deleted before adding it again. I get a "Run-Time error '13': Type
mismatch" message when i run it at the point mentioned below.

Any help much appreciated.


Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

'Application.Workbooks(wb).Names("Part_Family_Desc ription").Delete<= ??

'<<== ERROR MESSAGE AT THIS POINT ======
Workbooks(wb).Names.Add Name:="Part_Family_Description", _
RefersTo:=Workbooks(wb).Sheets("sh").Range("D3",
Range("D65536").End(xlUp))

cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub

--
Les

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Variable Names Range - Help Needed

I should have added this will also reduce the size of the named range if
records are deleted

Mike

"Mike H" wrote:

Les,

Maybe this

Dim rng As Range
Set rng = Range("Part_Family_Description")
lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
added = lastrow - rng.Rows.Count
rng.Resize(rng.Rows.Count + added).Name = "Part_Family_Description"

Mike

"Les" wrote:

Hi all,

I am using the code below to try and resize the range in case a record has
been added to the bottom of this range. I am not sure if the "Old" range must
first be deleted before adding it again. I get a "Run-Time error '13': Type
mismatch" message when i run it at the point mentioned below.

Any help much appreciated.


Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

'Application.Workbooks(wb).Names("Part_Family_Desc ription").Delete<= ??

'<<== ERROR MESSAGE AT THIS POINT ======
Workbooks(wb).Names.Add Name:="Part_Family_Description", _
RefersTo:=Workbooks(wb).Sheets("sh").Range("D3",
Range("D65536").End(xlUp))

cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub

--
Les

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Variable Names Range - Help Needed

Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

wb.Names.Add Name:="Part_Family_Description", _
RefersTo:="='" & sh.Name & "'!" & Range(sh.Range("D3"),
sh.Range("D65536").End(xlUp)).Address


cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub





--
__________________________________
HTH

Bob

"Les" wrote in message
...
Hi all,

I am using the code below to try and resize the range in case a record has
been added to the bottom of this range. I am not sure if the "Old" range
must
first be deleted before adding it again. I get a "Run-Time error '13':
Type
mismatch" message when i run it at the point mentioned below.

Any help much appreciated.


Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

'Application.Workbooks(wb).Names("Part_Family_Desc ription").Delete<= ??

'<<== ERROR MESSAGE AT THIS POINT ======
Workbooks(wb).Names.Add Name:="Part_Family_Description", _
RefersTo:=Workbooks(wb).Sheets("sh").Range("D3",
Range("D65536").End(xlUp))

cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub

--
Les



  #5   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Variable Names Range - Help Needed

Thanx Mike H
--
Les


"Mike H" wrote:

Les,

Maybe this

Dim rng As Range
Set rng = Range("Part_Family_Description")
lastrow = Cells(Cells.Rows.Count, "D").End(xlUp).Row
added = lastrow - rng.Rows.Count
rng.Resize(rng.Rows.Count + added).Name = "Part_Family_Description"

Mike

"Les" wrote:

Hi all,

I am using the code below to try and resize the range in case a record has
been added to the bottom of this range. I am not sure if the "Old" range must
first be deleted before adding it again. I get a "Run-Time error '13': Type
mismatch" message when i run it at the point mentioned below.

Any help much appreciated.


Private Sub UserForm_Initialize()
'
Dim wb As Workbook, sh As Worksheet
Set wb = Workbooks("Logistics_Cost_TM_Input.xls")
Set sh = Sheets("Part_Family")

'Application.Workbooks(wb).Names("Part_Family_Desc ription").Delete<= ??

'<<== ERROR MESSAGE AT THIS POINT ======
Workbooks(wb).Names.Add Name:="Part_Family_Description", _
RefersTo:=Workbooks(wb).Sheets("sh").Range("D3",
Range("D65536").End(xlUp))

cmb_PrtFam.RowSource = "Part_Family!Part_Family_Description"
End Sub

--
Les

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
Range("C100:D200").Select with variable names Fan924 Excel Programming 2 October 15th 07 03:54 PM
Variable names for named range Barb Reinhardt Excel Discussion (Misc queries) 4 March 19th 07 05:37 PM
using a "variable" in range names Adam Kroger Excel Discussion (Misc queries) 9 December 11th 05 07:17 PM
'ActiveWorkbook.Names.Add Name:' how to make range variable? TeeSea Excel Programming 1 June 9th 05 03:42 PM
Macro in VBA: Setting a variable print range HELP NEEDED!! Ron de Bruin Excel Programming 1 July 21st 04 05:45 PM


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