Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Range name Database only works on one sheet

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Range name Database only works on one sheet

Worked it out.

Added code for each Command Button to Delete the Name, then re-create with
the new range.

Sheets("Guidance").Select
ActiveWorkbook.Names("Database").Delete
Range("A3:H20").Select
ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
"=Guidance!R3C1:R20C8"

May be messy, but it worked. Starting to enjoy Excel VBA.

--
Brian McCaffery


"Brian" wrote:

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Range name Database only works on one sheet

Instead of using a workbook level range name, maybe using a sheet level name
would be better:

Range("A3:H33").Name = "Database"
becomes
me.Range("A3:H33").Name = "'" & me.name & "'!" & "Database"

Assuming that each of those buttons are on separate sheets.

or

with worksheets("somesheetnamehere")
.Range("A3:H33").Name = "'" & .name & "'!" & "Database"
end with

Since you're working with names, get Jan Karel Pieterse's (with Charles Williams
and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

Brian wrote:

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Range name Database only works on one sheet

Dave,

Thanks for the reply. I'll check that out.

May I ask one more question? In the code, I am tryingh to make the list
expand. At the moment, it will only allow me to add one new record. I have
search the forums, and google, but for the life of nme, I can't seem to get
anything to work. How do I amend the range to allow for the expansion?

Unfortunatly, this week is when my wife is on her annual trip to see her
mother; She is an excel VBA guru.

Private Sub CommandButton1_Click()
Sheets("GSOPs").Select
ActiveWorkbook.Names("Database").Delete
Range("A3:H32").Select
ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
"=GSOPs!R3C1:R25C8"
Range("A3:H32").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery


"Dave Peterson" wrote:

Instead of using a workbook level range name, maybe using a sheet level name
would be better:

Range("A3:H33").Name = "Database"
becomes
me.Range("A3:H33").Name = "'" & me.name & "'!" & "Database"

Assuming that each of those buttons are on separate sheets.

or

with worksheets("somesheetnamehere")
.Range("A3:H33").Name = "'" & .name & "'!" & "Database"
end with

Since you're working with names, get Jan Karel Pieterse's (with Charles Williams
and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

Brian wrote:

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Range name Database only works on one sheet

I'd do something like:

dim LastRow as long
with me 'the sheet with the button
'can column A be used to determine if the row should be included?
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("A3:H" & lastrow).name = "'" & .name & "'!Database"
end with
SendKeys "%w", False
me.ShowDataForm

=====
You may want to look at defining a worksheet level name (local name) that
expands and contracts when data is added/deleted.

Debra Dalgleish explains it he
http://contextures.com/xlNames01.html#Dynamic

Make sure you make it a local name: GSOPs!database




Brian wrote:

Dave,

Thanks for the reply. I'll check that out.

May I ask one more question? In the code, I am tryingh to make the list
expand. At the moment, it will only allow me to add one new record. I have
search the forums, and google, but for the life of nme, I can't seem to get
anything to work. How do I amend the range to allow for the expansion?

Unfortunatly, this week is when my wife is on her annual trip to see her
mother; She is an excel VBA guru.

Private Sub CommandButton1_Click()
Sheets("GSOPs").Select
ActiveWorkbook.Names("Database").Delete
Range("A3:H32").Select
ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
"=GSOPs!R3C1:R25C8"
Range("A3:H32").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery

"Dave Peterson" wrote:

Instead of using a workbook level range name, maybe using a sheet level name
would be better:

Range("A3:H33").Name = "Database"
becomes
me.Range("A3:H33").Name = "'" & me.name & "'!" & "Database"

Assuming that each of those buttons are on separate sheets.

or

with worksheets("somesheetnamehere")
.Range("A3:H33").Name = "'" & .name & "'!" & "Database"
end with

Since you're working with names, get Jan Karel Pieterse's (with Charles Williams
and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

Brian wrote:

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery


--

Dave Peterson


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 683
Default Range name Database only works on one sheet

Thanks for all your help Dave.

Used Debra's instructions. All working (nearly).

Have a few minor things to fix. If I get stuck you will probably see another
post, but I have a few ideas I want to try first.

Thanks again
--
Brian McCaffery


"Dave Peterson" wrote:

I'd do something like:

dim LastRow as long
with me 'the sheet with the button
'can column A be used to determine if the row should be included?
lastrow = .cells(.rows.count,"A").end(xlup).row
.range("A3:H" & lastrow).name = "'" & .name & "'!Database"
end with
SendKeys "%w", False
me.ShowDataForm

=====
You may want to look at defining a worksheet level name (local name) that
expands and contracts when data is added/deleted.

Debra Dalgleish explains it he
http://contextures.com/xlNames01.html#Dynamic

Make sure you make it a local name: GSOPs!database




Brian wrote:

Dave,

Thanks for the reply. I'll check that out.

May I ask one more question? In the code, I am tryingh to make the list
expand. At the moment, it will only allow me to add one new record. I have
search the forums, and google, but for the life of nme, I can't seem to get
anything to work. How do I amend the range to allow for the expansion?

Unfortunatly, this week is when my wife is on her annual trip to see her
mother; She is an excel VBA guru.

Private Sub CommandButton1_Click()
Sheets("GSOPs").Select
ActiveWorkbook.Names("Database").Delete
Range("A3:H32").Select
ActiveWorkbook.Names.Add Name:="Database", RefersToR1C1:= _
"=GSOPs!R3C1:R25C8"
Range("A3:H32").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery

"Dave Peterson" wrote:

Instead of using a workbook level range name, maybe using a sheet level name
would be better:

Range("A3:H33").Name = "Database"
becomes
me.Range("A3:H33").Name = "'" & me.name & "'!" & "Database"

Assuming that each of those buttons are on separate sheets.

or

with worksheets("somesheetnamehere")
.Range("A3:H33").Name = "'" & .name & "'!" & "Database"
end with

Since you're working with names, get Jan Karel Pieterse's (with Charles Williams
and Matthew Henson) Name Manager:

You can find it at:
NameManager.Zip from http://www.oaltd.co.uk/mvp

Brian wrote:

All,

The problem I have is that I have 4 sheets containing data. I want to call
the showdataform from a command buttons based on the sheets. I have named the
range "database" in the first sheet, but if I try to apply it to the second
sheet, then all command buttons pick up the last assigned "database" name. In
other words, is there a way to have the database name in all sheet ranges?

Private Sub CommandButton1_Click()

Range("A3:H33").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Private Sub CommandButton2_Click()
Range("A3:H20").Name = "Database"
SendKeys "%w", False
ActiveSheet.ShowDataForm
End Sub

Thanks,
--
Brian McCaffery

--

Dave Peterson


--

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
works database - converting elwjr Excel Discussion (Misc queries) 1 December 13th 05 02:30 PM
converting from works database elwjr Excel Discussion (Misc queries) 0 December 11th 05 04:36 PM
OT? Microsoft Works Database Import? Lee Harris Excel Worksheet Functions 2 November 22nd 05 03:33 PM
Transfering Database From Excel to Works Alex Excel Discussion (Misc queries) 0 April 19th 05 03:09 AM
Range only works when Sheet Name is "Sheet1" paul reed Excel Programming 4 September 14th 03 08:37 PM


All times are GMT +1. The time now is 05:38 PM.

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"