Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default parameter queries in macros

Hello, The following macro works great!

Sub hidecolumns()
Columns("d:fz").Hidden = False
Dim sPrompt As String
sPrompt = "Enter 1 for Initial DHS Recommendation" & vbNewLine & "Ente
2 for Project Recommendation" & vbNewLine & "Enter 3 for Final DH
Recommendation" & vbNewLine & "Enter 4 for Project/DHS Matches"
vbNewLine & "Enter 5 for DHS VDAT Modules"
x = InputBox(sPrompt)
For Each c In Range("d1:fz1")
If Right(c, 1) < x Then c.EntireColumn.Hidden = True
Next
End Sub

However, I would like to change this macro or create a new one a
follows:

If you enter "5" in the parameter query, I would like it to displa
only the columns that:

* contain a 5 in the header (as it is now) AND
* have a D in at least one cell of that column

I don't have to put this logic in this particular macro. I can put i
in a new/separate macro if that is less complicated.

Thx. much! (file attached)

lindas

Attachment filename: calwin food stamps training analysis-dhs vdat-demo.xl
Download attachment: http://www.excelforum.com/attachment.php?postid=62450
--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default parameter queries in macros

This should do it

Sub find5andD()
hideall 'call your macro to hide all columns
For Each col In Columns("d:fz")
If Right(Cells(1, col.Column), 1) = 5 And _
Application.CountIf(col, "D") 0 Then col.Hidden = False
Next
End Sub
--
Don Guillett
SalesAid Software

"lindasf " wrote in message
...
Hello, The following macro works great!

Sub hidecolumns()
Columns("d:fz").Hidden = False
Dim sPrompt As String
sPrompt = "Enter 1 for Initial DHS Recommendation" & vbNewLine & "Enter
2 for Project Recommendation" & vbNewLine & "Enter 3 for Final DHS
Recommendation" & vbNewLine & "Enter 4 for Project/DHS Matches" &
vbNewLine & "Enter 5 for DHS VDAT Modules"
x = InputBox(sPrompt)
For Each c In Range("d1:fz1")
If Right(c, 1) < x Then c.EntireColumn.Hidden = True
Next
End Sub

However, I would like to change this macro or create a new one as
follows:

If you enter "5" in the parameter query, I would like it to display
only the columns that:

* contain a 5 in the header (as it is now) AND
* have a D in at least one cell of that column

I don't have to put this logic in this particular macro. I can put it
in a new/separate macro if that is less complicated.

Thx. much! (file attached)

lindasf

Attachment filename: calwin food stamps training analysis-dhs

vdat-demo.xls
Download attachment:

http://www.excelforum.com/attachment.php?postid=624509
---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default parameter queries in macros

Try this:

Sub hidecolumns()
Columns("d:fz").Hidden = False
Dim sPrompt As String
sPrompt = "Enter 1 for Initial DHS Recommendation" & vbNewLine & "Ente
2 for Project Recommendation" & vbNewLine & "Enter 3 for Final DH
Recommendation" & vbNewLine & "Enter 4 for Project/DHS Matches"
vbNewLine & "Enter 5 for DHS VDAT Modules"
x = InputBox(sPrompt)
Set myRange = Range("A1").CurrentRegion
LastRow = myRange.Cells(myRange.Cells.Count).Row
For Each c In Range("d1:fz1")
If Right(c, 1) < x Then
c.EntireColumn.Hidden = True
Else:
Hide = True
j = c.Column
For i = 2 To LastRow
If Cells(i, j) = "D" Then Hide = False
Next i
If Hide Then c.EntireColumn.Hidden = True
End If
Next
End Su

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default parameter queries in macros

Thx much guys

--
Message posted from http://www.ExcelForum.com

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,337
Default parameter queries in macros

glad to help

--
Don Guillett
SalesAid Software

"lindasf " wrote in message
...
Thx much guys!


---
Message posted from
http://www.ExcelForum.com/



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
Table queries not updating when parameter changes Benjamin Peikes Excel Discussion (Misc queries) 4 April 24th 12 12:03 PM
Parameter queries in Excel 2007 Sam in Chicago Excel Discussion (Misc queries) 0 April 11th 08 10:12 PM
Queries in Macros Lilbit Excel Worksheet Functions 1 April 9th 08 07:34 PM
MS query--can it handle parameter queries from Access? Dave F Excel Discussion (Misc queries) 0 September 13th 06 02:41 PM
Where can I learn how to create parameter queries in Excel? Mark Excel Discussion (Misc queries) 1 January 23rd 06 02:31 PM


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