dropkickweasel
Board Regular
- Joined
- Feb 2, 2014
- Messages
- 70
Hi,
I think what I'm trying to do is logical and I'm just unaware of the syntax to make it run.
I have a sheet called "Board".
On "Board" I have several named ranges.
Four of them refer to tenants ("Tenant1" etc).
Many more refer to flats in a building ("Flat23, etc).
I have a userform with option buttons to track which tenants are in which flats.
The option buttons are in two groups: Four buttons for Tenants1 - 4, (called "Tenant1" and grouped as "Tenants"), and many more for the flats (called "Flat23" and grouped as "Flats").
The Tenant named ranges contain information about each tenant.
The Flat named ranges are empty locations on the sheet into which the tenant information is to be copied/pasted.
Using the following code:
I am able to copy/paste the relevant tenant information into the location "Flat23".
What I can't work out is how to make the destination range to be a variable dependent on the Flat location selected with the second set of option buttons.
I'm fairly new to VBA so am trying to piece together what I can and have come up with this so far:
But I'm getting a 'Run-time error 424: Object required' error message on the second line and I don't know what the appropriate syntax should be to set the variable as the result of the option button selection.
I'm hoping that once someone is able to help me with that, then changing the range in the first part of the code to
will put the tenant information in the right place.
As a side note, I'm assuming it's fairly bad practice to have named ranges and option buttons called the same thing. Is it problematic or just bad practice?
I think what I'm trying to do is logical and I'm just unaware of the syntax to make it run.
I have a sheet called "Board".
On "Board" I have several named ranges.
Four of them refer to tenants ("Tenant1" etc).
Many more refer to flats in a building ("Flat23, etc).
I have a userform with option buttons to track which tenants are in which flats.
The option buttons are in two groups: Four buttons for Tenants1 - 4, (called "Tenant1" and grouped as "Tenants"), and many more for the flats (called "Flat23" and grouped as "Flats").
The Tenant named ranges contain information about each tenant.
The Flat named ranges are empty locations on the sheet into which the tenant information is to be copied/pasted.
Using the following code:
Code:
Private Sub PlaceTenantButton_Click()
If Me.Tenant1.Value Then Board.Range("Flat23").Value = Board.Range("Tenant1").Value
If Me.Tenant2.Value Then Board.Range("Flat23").Value = Board.Range("Tenant2").Value
If Me.Tenant3.Value Then Board.Range("Flat23").Value = Board.Range("Tenant3").Value
If Me.Tenant4.Value Then Board.Range("Flat23").Value = Board.Range("Tenant4").Value
End Sub
I am able to copy/paste the relevant tenant information into the location "Flat23".
What I can't work out is how to make the destination range to be a variable dependent on the Flat location selected with the second set of option buttons.
I'm fairly new to VBA so am trying to piece together what I can and have come up with this so far:
Code:
Dim Flat As Range
Set Flat = OptionButton.Flats
If Me.Flat23.Value Then Flat = Range("Flat23")
If Me.Flat24.Value Then Flat = Range("Flat24")
But I'm getting a 'Run-time error 424: Object required' error message on the second line and I don't know what the appropriate syntax should be to set the variable as the result of the option button selection.
I'm hoping that once someone is able to help me with that, then changing the range in the first part of the code to
Code:
If Me.Tenant1.Value Then Board.Range(Flat).Value = Board.Range("Tenant1").Value
As a side note, I'm assuming it's fairly bad practice to have named ranges and option buttons called the same thing. Is it problematic or just bad practice?