Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving labels based on criteria (visible & not visible)

Status
Not open for further replies.

senators40

Technical User
Jan 7, 2003
68
CA
Hi,

I have an excel macro in Excel 2003 and I have 4 labels. The four labels are

Salaries, Land, Buildings, Other If they all have dollars then they all will be shown at .top of 10, 20, 30, 40 etc

However if Land is 0 I want to be able to move buildings to .top of 20, Other to .top of 30 etc.

Or another example Salaries & Buildings are 0 so I only need Land and Other - I want those at .top of 10 & 20.

I think they should be separate labels as I also have this criteria for option buttons as well.

I could write a lot of code to move the items to the correct position but I am pretty sure that there is a way to move the items easier and with less repetition.

Any help would be appreciated.

Thanks,

Jeff
 
there is a way to move the items easier and with less repetition
than what ?
IOW, what have tried so far ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 



...and maybe post a concrete example of your data table.

Skip,
[sub]
[glasses] To be safe on the [red]FOURTH[/red],
Don't take a [red]FIFTH[/red] on the [red]THIRD[/red]
Or you might not come [red]FORTH[/red] on the [red]FIFTH[/red]
[red][highlight blue]FORTH[/highlight][/red][white][highlight red]WITH[/highlight][/white] [tongue][/sub]
 
If Salaries.Text <> 0 and Land.Text <> 0 and Building.Text <> 0 and Other.Text = 0 then
Other.Visible = False

Elseif Salaries.Text <> 0 and Land.Text = 0 and Buildings.Text <> 0 and Other.Text <> 0 then
Land.Visible = False
Building.Top = 20
Other.Top = 30

Elseif Salaries.Text <> 0 and Land.Text <> 0 and Buldings.Text = 0 and Other.Text <> 0 then
Buildings.Visible = False
Other.Top = 30

Elseif Salaries.Text = 0 and Land.Text <> 0 and Buildings.Text <> 0 and Other.Text <> 0 then
Salaries.Visisble = False
Land.Top = 10
Buildings.Top = 20
Other.Top = 30

Elseif Salaries.Text = 0 and Land.Text = 0 and Buildings.Text <> 0 and Other.Text <> 0 then
Salaries.Visisble = False
Land.Visible = False
Buildings.Top = 10
Other.Top = 20

Elseif Salaries.Text = 0 and Land.Text <> 0 and Buildings.Text = 0 and Other.Text = 0 then
Salaries.Visisble = False
Buildings.Visible = False
Land.Top = 10
Other.Top = 20

etc…

end if

As you can see I have to go through all possible combinations of whether the salaries, land, buildings, and other are 0 and move the items accordingly.

Jeff
 
Typed, untested:
Code:
Dim myTop As Integer
myTop = 10
If Salaries.Text <> 0 Then
  Salaries.Visible = True
  Salaries.Top = myTop
  myTop = myTop + 10
Else
  Salaries.Visible = False
End If
If Land.Text <> 0 Then
  Land.Visible = True
  Land.Top = myTop
  myTop = myTop + 10
Else
  Land.Visible = False
End If
If Building.Text <> 0 Then
  Building.Visible = True
  Building.Top = myTop
  myTop = myTop + 10
Else
  Building.Visible = False
End If
If Other.Text <> 0 Then
  Other.Visible = True
  Other.Top = myTop
  myTop = myTop + 10
Else
  Other.Visible = False
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top