Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Using ComboBoxes to get range of values

Hi,
I'm writting a sub that I had in an existing spreadsheet. Basically,
the sub would search how would be retiring in a certain year, and
display a list of these individuals, range called "Des". Problem now
is that H/R doesn't want just one year to be displayed, but a range of
years.

I've written out the error message, but dim'd values for the
ComboBoxes (CB1 & CB3) CB1 is the beginning year range, CB3 is the
ending year range.
I can't figure out how to pull a range of years over.

Range names are. "List" contains a list of years, (2004 - 2018) and
"And" contains various companies this division owns, if H/R wants to
get to company specific.

Does anyone have any ideas on how to write the code for a range of
years?

Thanks,
-K

Sub masterRep1Search()

Dim CB1 As Integer
Dim CB3 As Integer
Dim Msg, Title, Style, Response
CB1 = Worksheets("Master Filter").Range("D3").Value
CB3 = Worksheets("Master Filter").Range("I3").Value

'Error Message
If CB1 CB3 Then
Msg = "End Year has to be greater than or equal to the
beginning year."
Style = vbOKOnly + vbCritical
Title = "Selection Error"
Response = MsgBox(Msg, Style, Title)
Exit Sub
End If

'Pulling of the Data
Range("List").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"And"), CopyToRange:=Range("Des"), Unique:=False
ActiveWindow.ScrollRow = 1
ActiveWindow.SmallScroll ToRight:=1
ActiveWindow.ScrollColumn = 1
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Using ComboBoxes to get range of values

Sub masterRep1Search()

Dim CB1 As Integer
Dim CB3 As Integer
Dim Msg, Title, Style, Response
CB1 = Worksheets("Master Filter").Range("D3").Value
CB3 = Worksheets("Master Filter").Range("I3").Value

'Error Message
If CB1 CB3 Then
Msg = "End Year has to be greater than or equal to the
beginning year."
Style = vbOKOnly + vbCritical
Title = "Selection Error"
Response = MsgBox(Msg, Style, Title)
Exit Sub
End If

'Pulling of the Data
Range("List").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"And"), CopyToRange:=Range("Des"), Unique:=False
ActiveWindow.ScrollRow = 1
ActiveWindow.SmallScroll ToRight:=1
ActiveWindow.ScrollColumn = 1
End Sub

Your criteria range would be

Year Year
="=2003" ="<=2005"

so all you need to do is redefine your critiera range and build the criteria
using you combobox selections.

if you don't have a year column, but a date column, then you would build
your dates like

"=" & """=" & format(dateserial(cb1,1,1),"mm/dd/yyyy") & """"
"=" & """<=" & format(dateserial(cb3,12,31),"mm/dd/yyyy") & """"


--
Regards,
Tom Ogilvy

"Kirk Lewis" wrote in message
om...
Hi,
I'm writting a sub that I had in an existing spreadsheet. Basically,
the sub would search how would be retiring in a certain year, and
display a list of these individuals, range called "Des". Problem now
is that H/R doesn't want just one year to be displayed, but a range of
years.

I've written out the error message, but dim'd values for the
ComboBoxes (CB1 & CB3) CB1 is the beginning year range, CB3 is the
ending year range.
I can't figure out how to pull a range of years over.

Range names are. "List" contains a list of years, (2004 - 2018) and
"And" contains various companies this division owns, if H/R wants to
get to company specific.

Does anyone have any ideas on how to write the code for a range of
years?

Thanks,
-K

Sub masterRep1Search()

Dim CB1 As Integer
Dim CB3 As Integer
Dim Msg, Title, Style, Response
CB1 = Worksheets("Master Filter").Range("D3").Value
CB3 = Worksheets("Master Filter").Range("I3").Value

'Error Message
If CB1 CB3 Then
Msg = "End Year has to be greater than or equal to the
beginning year."
Style = vbOKOnly + vbCritical
Title = "Selection Error"
Response = MsgBox(Msg, Style, Title)
Exit Sub
End If

'Pulling of the Data
Range("List").AdvancedFilter Action:=xlFilterCopy,
CriteriaRange:=Range( _
"And"), CopyToRange:=Range("Des"), Unique:=False
ActiveWindow.ScrollRow = 1
ActiveWindow.SmallScroll ToRight:=1
ActiveWindow.ScrollColumn = 1
End Sub



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
calculate values in an unlimited range of cells in a column WITHOUTalso calculating values that had previously been filtered AGAINST? yadang Excel Discussion (Misc queries) 2 October 1st 09 06:18 PM
SUMPRODUCT or SUMIF if any values in a range equal any values in another range PCLIVE Excel Worksheet Functions 3 July 15th 09 07:43 PM
Search/Filter to find values in another range based on two cell values Andy Excel Programming 2 April 29th 04 04:08 PM
Limiting values in comboboxes. mika.[_2_] Excel Programming 2 November 27th 03 02:02 PM


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