Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default Offset from new name based on what's checked in Userform

XL2000

I have a sheet that uses a userform to add new names to a list in colA
Early in my code, New_Member is set from userform textbox:
New_Member = UCase$(frmAddMem.tbNewName.Text)

Later my code puts new name at the bottom of current list in ColA:
Set rng = Range(Cells(4, 1), Cells(4, 1).End(xlDown).Offset(1, 0))
rng(rng.Rows.Count) = New_Member

I've added some checkboxes to the userform and renamed them:

cbGH to show name is a group home resident if checked
cbMON to show member attends on Monday if checked
cbTUE to show member attends on Tuesday if checked
and so on through Friday

Cols B:F will house u or l (el) formatted as Wingding to indicate who
attends on a given weekday from a group home or non-group home living
arrangement. I currently enter these manually

Code I want to add:
If cbGH is checked and cbTUE and cbTHU are checked a 'u' will offset from
member name in Cols C and E
If cbGH is unchecked and cbMON, cbWED and cbFRI are checked an 'l' will
offset from member name in Cols B, D, and F

Above are just two scenarios. Any member from any group can attend on any
day, some all 5, some just 1 or any mix thereof.

I want code to look at the state of the checkboxes and act accordingly to
populate B:F with u's or l's or leave any unchecked empty.

I would be willing the change the name property of the boxes to make things
easier, if required.

--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Offset from new name based on what's checked in Userform

Dim rng as Range
set rng = Cells(4,1).End(xldown).Offset(1,0)
rng.Value = new_member
if cbMON then
With rng.offset(0,1)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbTUE then
With rng.offset(0,2)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbWED then
With rng.offset(0,3)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbTHU then
With rng.offset(0,4)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbFRI then
With rng.offset(0,5)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if

--
Regards,
Tom Ogilvy


"David" wrote in message
...
XL2000

I have a sheet that uses a userform to add new names to a list in colA
Early in my code, New_Member is set from userform textbox:
New_Member = UCase$(frmAddMem.tbNewName.Text)

Later my code puts new name at the bottom of current list in ColA:
Set rng = Range(Cells(4, 1), Cells(4, 1).End(xlDown).Offset(1, 0))
rng(rng.Rows.Count) = New_Member

I've added some checkboxes to the userform and renamed them:

cbGH to show name is a group home resident if checked
cbMON to show member attends on Monday if checked
cbTUE to show member attends on Tuesday if checked
and so on through Friday

Cols B:F will house u or l (el) formatted as Wingding to indicate who
attends on a given weekday from a group home or non-group home living
arrangement. I currently enter these manually

Code I want to add:
If cbGH is checked and cbTUE and cbTHU are checked a 'u' will offset from
member name in Cols C and E
If cbGH is unchecked and cbMON, cbWED and cbFRI are checked an 'l' will
offset from member name in Cols B, D, and F

Above are just two scenarios. Any member from any group can attend on any
day, some all 5, some just 1 or any mix thereof.

I want code to look at the state of the checkboxes and act accordingly to
populate B:F with u's or l's or leave any unchecked empty.

I would be willing the change the name property of the boxes to make

things
easier, if required.

--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default Offset from new name based on what's checked in Userform

Tom Ogilvy wrote

Dim rng as Range
set rng = Cells(4,1).End(xldown).Offset(1,0)
rng.Value = new_member
if cbMON then
With rng.offset(0,1)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbTUE then
With rng.offset(0,2)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbWED then
With rng.offset(0,3)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbTHU then
With rng.offset(0,4)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if
if cbFRI then
With rng.offset(0,5)
.Value = iif(cbGH,"u","l")
.Font.Name = "Wingdings"
End With
end if


As written, it puts the name at the bottom of the list, but no u's or
l's, and later my line:
rng.Resize(, cols).Sort Key1:=Range("A1"), Order1:=xlAscending
fails to sort.

I changed all rng.offsets to rng(rng.Rows.Count).Offset to match existing
code and sort worked, but still no u's or l's :{

If it helps, here is entire original code:

Sub Add_Member()
Dim rng As Range, New_Member As String
Dim cols As Long
frmAddMem.Show
New_Member = UCase$(frmAddMem.tbNewName.Text)
If New_Member = "" Then Unload frmAddMem: Exit Sub
Unload frmAddMem
Application.ScreenUpdating = False
cols = ActiveSheet.UsedRange.Columns.Count
Set rng = Range(Cells(4, 1), Cells(4, 1).End(xlDown).Offset(1, 0))
rng(rng.Rows.Count) = New_Member
rng.Resize(, cols).Sort Key1:=Range("A1"), Order1:=xlAscending
Application.ScreenUpdating = True
End Sub

--
David
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default Offset from new name based on what's checked in Userform

Tom Ogilvy wrote

<snip

Tada!!

Sub Add_Member()
Dim rng As Range, New_Member As String, Maxed As String
Dim cols As Long
frmAddMem.Show
New_Member = UCase$(frmAddMem.tbNewName.Text)
If New_Member = "" Then Unload frmAddMem: Exit Sub
Application.ScreenUpdating = False
cols = ActiveSheet.UsedRange.Columns.Count
Set rng = Range(Cells(4, 1), Cells(4, 1).End(xlDown).Offset(1, 0))
rng(rng.Rows.Count) = New_Member
If frmAddMem.cbMON Then rng(rng.Rows.Count).Offset(0, 1).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbTUE Then rng(rng.Rows.Count).Offset(0, 2).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbWED Then rng(rng.Rows.Count).Offset(0, 3).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbTHU Then rng(rng.Rows.Count).Offset(0, 4).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbFRI Then rng(rng.Rows.Count).Offset(0, 5).Value = IIf
(frmAddMem.cbGH, "u", "l")
Unload frmAddMem
rng.Resize(, cols).Sort Key1:=Range("A1"), Order1:=xlAscending
Application.ScreenUpdating = True
End Sub

For some reason I had to precede all cb's with frmAddMem. and wait to
Unload frmAddMem until they were processed.

Thanks for leading the way!

--
David
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Offset from new name based on what's checked in Userform

Sub Add_Member()
Dim rng As Range, New_Member As String, Maxed As String
Dim cols As Long
With frmAddMem
.Show
New_Member = UCase$(.tbNewName.Text)
If New_Member = "" Then Unload frmAddMem: Exit Sub
Application.ScreenUpdating = False
cols = ActiveSheet.UsedRange.Columns.Count
Set rng = Cells(4, 1).End(xlDown).Offset(1, 0)
rng = New_Member
If .cbMON Then rng.Offset(0, 1).Value = IIf(.cbGH, "u", "l")
If .cbTUE Then rng.Offset(0, 2).Value = IIf(.cbGH, "u", "l")
If .cbWED Then rng.Offset(0, 3).Value = IIf(.cbGH, "u", "l")
If .cbTHU Then rng.Offset(0, 4).Value = IIf(.cbGH, "u", "l")
If .cbFRI Then rng.Offset(0, 5).Value = IIf(.cbGH, "u", "l")
Unload frmAddMem
Range(cells(4,1),rng).Resize(, cols).Sort _
Key1:=Range("A1"), Order1:=xlAscending
Application.ScreenUpdating = True
End With
End Sub

when you show the userform, the code stops execution until the userform is
hidden. Code not in the userform module must be qualified with the userform
name. Using WITH makes this much more compact.

--
Regards,
Tom Ogilvy



"David" wrote in message
...
Tom Ogilvy wrote

<snip

Tada!!

Sub Add_Member()
Dim rng As Range, New_Member As String, Maxed As String
Dim cols As Long
frmAddMem.Show
New_Member = UCase$(frmAddMem.tbNewName.Text)
If New_Member = "" Then Unload frmAddMem: Exit Sub
Application.ScreenUpdating = False
cols = ActiveSheet.UsedRange.Columns.Count
Set rng = Range(Cells(4, 1), Cells(4, 1).End(xlDown).Offset(1, 0))
rng(rng.Rows.Count) = New_Member
If frmAddMem.cbMON Then rng(rng.Rows.Count).Offset(0, 1).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbTUE Then rng(rng.Rows.Count).Offset(0, 2).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbWED Then rng(rng.Rows.Count).Offset(0, 3).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbTHU Then rng(rng.Rows.Count).Offset(0, 4).Value = IIf
(frmAddMem.cbGH, "u", "l")
If frmAddMem.cbFRI Then rng(rng.Rows.Count).Offset(0, 5).Value = IIf
(frmAddMem.cbGH, "u", "l")
Unload frmAddMem
rng.Resize(, cols).Sort Key1:=Range("A1"), Order1:=xlAscending
Application.ScreenUpdating = True
End Sub

For some reason I had to precede all cb's with frmAddMem. and wait to
Unload frmAddMem until they were processed.

Thanks for leading the way!

--
David





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 195
Default Offset from new name based on what's checked in Userform

Tom Ogilvy wrote

when you show the userform, the code stops execution until the
userform is hidden. Code not in the userform module must be qualified
with the userform name. Using WITH makes this much more compact.


I like it. Thanks.
I mistakenly thought that my cmdDone_Click line Me.Hide in the userform
module accomplished that.

Added bonus: the modified/compacted 'Set rng = ...' line. I'll incorporate
it in similar Add_Member modules in other workbooks.

--
David
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
Using checkboxes, can I write formulas based on what is checked? Liz Excel Worksheet Functions 2 March 14th 08 11:32 PM
Calculating percentages based on the number of checked boxes in a column [email protected] Excel Worksheet Functions 7 June 6th 07 01:08 PM
Calculating percentages based on the number of checked boxes in a column [email protected] Excel Discussion (Misc queries) 1 June 6th 07 12:02 PM
Print a selection based on checked checkboxes Stefan van der Hooft Excel Worksheet Functions 0 May 2nd 07 09:34 AM
checkbox - default checked or un-checked barrfly Excel Programming 1 December 22nd 03 05:00 PM


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