Solved

Conditional print of Excel cells from VB

Posted on 1999-01-11
5
157 Views
Last Modified: 2010-05-03
I have a VB program that accesses an Excel worksheet.

What I want to do is when I finish to send data, print ONLY the rows of cells that don't have blank or zero. For example, I make a statistic of the employees' laboral absences this year and as result I have:

Employee 1     10
Employee 2      3
Employee 3      0
Employee 4      1

How can I make to print the worksheet WITHOUT printing Employee 3?

I have VB 5.0 Enterprise ad Office 97 Pro. Thanks in advance.

As you see, I have the basics on VB, but I don't know much about Excel and VBA. Please send a simple example code.
0
Comment
Question by:BETTY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Expert Comment

by:ameba
ID: 1455504
Can you make to print the worksheet WITH printing Employee 3?
0
 
LVL 15

Expert Comment

by:ameba
ID: 1455505
If you can, to hide a range or selection, use
    Selection.Font.ColorIndex = 2 ' white

Use Macro Recorder in Excel to generate your code.
0
 
LVL 3

Accepted Solution

by:
sduckett earned 100 total points
ID: 1455506
Try the following code which will filter out your unwanted records, print the table, then cancel the filter.

Assumptions:
Your worksheet is called "Sheet1".
The absence info is in column 2.
Cell A1 is part of your table. (If not, change 'Cells(1,1)' with the topmost left cell of your table)



Sub ExcludeBlanks()

Const ThisWorksheet = "Sheet1"
Const AbsencesColumn = 2

With Worksheets(ThisWorksheet).Cells(1, 1).CurrentRegion
    .AutoFilter field:=AbsencesColumn, Criteria1:=">0"
    .PrintOut
    .AutoFilter 'This with no parameters turns off Autofilter
End With

End Sub


PS Ameba's advice to use the Macro-Recorder is priceless for beginners. Don't expect the best code but it is a fast way to learn. Record a macro then improve it...
All the best.
0
 
LVL 1

Author Comment

by:BETTY
ID: 1455507
After checking sduckett's answer, I've found it's working well, although I had to retouch a little the code to fit my interest (Blame on me, I didn't explain all in detail in my question).

So I'm going to give the points him/her.

Despite this, ameba's trick is as easy as genial, so, please, go to question titled "From Betty to Ameba" and send any answer, I'll give you the 10 points.
0
 
LVL 1

Author Comment

by:BETTY
ID: 1455508
After checking sduckett's answer, I've found it's working well, although I had to retouch a little the code to fit my interest (Blame on me, I didn't explain all in detail in my question).

So I'm going to give the points him/her.

Despite this, ameba's trick is as easy as genial, so, please, go to question titled "From Betty to Ameba" and send any answer, I'll give you the 10 points.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spell Check in VB6 13 152
pop out of webbrowser1 control vba6 5 52
Send outlook email from VBS Script 2 67
Powerpoint 2013: Change cell reference in excel link 3 141
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question