Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

print out range with ignore highlighted cells

0

Hi Guys,

I  search for three days in  the  internet  all of  codes  are  useless for me   ,I  don't  find  anything  

I   have  data  in A:E. in column E  some  values  is  highlighted 

so  I  want ignoring  any  cell contains color and precede highlighted cell , just print  out  the last  data are not  highlihted .

thanks

Answer
Discuss

Discussion

Hello Omaran and welcome to the forum.

You haven't uploaded a sample file so I am not going to spend time writting code for this; but it could be achieved using VBA.
I understand your frustration. I encountered this a few years back only to learn that if you select only certain cells (non-contiguous) Excel treats each range selection as a different print job and prints the ranges separately. This was a one-time event and a small file so I made changes manually.
The ways to do this without VBA but are a bit tedious if your file is large. If there are only a few highlighted cells, you could change the font and fill to white (making note of which cells are being changed) then print your file, then change the font and fill colour back to what they originally were. If the fill colour is set by conditional formatting then the CF rules will need modifying and then be changed back. These two manual methods are ones that come to mind first. These methods could also be handled using VBA but need more info about the layout/size of your file (eg: is it 25 rows or 25,000+ rows)

Cheers   :-)
WillieD24 (rep: 557) Jul 6, '23 at 5:35 pm
Hi willie,
I  attached  the  file  .
as  you  see my  goal  should  print out  row12,13  
I  put  result in result  sheet   how  show  data in paper after print out .
my  real  data could  be 1000 rows 
thanks 
Omaran (rep: 8) Jul 6, '23 at 6:02 pm
Add to Discussion

Answers

0
Selected Answer

 Hi Omaran

From the file you attached to your question, it looks like you want to print only those transactions after the last cell in column E of worksheet Monthly which is manually filled red

At the top of that sheet in the revised file attached, you will find a green button labelled "Quick print last transactions". Click that and the last transactions will be printed (like your worksheet Result) to your printer. The button has the following macro (in Module1) assigned to it. I've added full comments so you can see what happens:

Sub PrintAfterHigh()

    ' Hide actions from user
    Application.ScreenUpdating = False
    ' find last used row in E
    LstRw = Cells(Rows.Count, "E").End(xlUp).Row

    ' loop backwards from there to row 2
    For n = LstRw To 2 Step -1
        ' check if cell is red
        If Cells(n, "E").Interior.Color = 255 Then
            ' if so, hide rows up to and including that
            Rows("2:" & n).Hidden = True
            ' stop looking
            Exit For
        End If
    Next n

    ' print results
    ActiveSheet.PrintOut
    ' unhide rows
    Rows("2:" & LstRw).Hidden = False
    ' reveal actions
    Application.ScreenUpdating = True
    ' tell user
    MsgBox "Printed last transactions- please collect from default printer"

End Sub

If you want to pick a printer, you'll need to replace the line in bold. If you change your highlight from red, you'll need to change the 255 value.

Hope this fixes your problem. If so, please remember to mark this Answer as Selected.

Discuss

Discussion

Hi John 
apprciated for  your  work !
well I  think  missing  sometthing  to  inform  you , this  is  my bad , sorry!
in this  time  I  can't  tell you  what  I  missed , how  your  code  goes,becuase I'm at  home and  no  print  in  my  home  I  will test it  at  work ,and  I will infom  you tomorrow.
sorry  for post  my  question in hurrying !
Omaran (rep: 8) Jul 7, '23 at 11:47 am
No problem! Thanks for responding 
John_Ru (rep: 6142) Jul 7, '23 at 2:17 pm
@John
Nice little macro. When I first read the post (before a file was posted) I thought the desire was to print everything except the highlighted cells. After reviewing the file posted, I believe you nailed it for what Omaran is looking to achieve.
WillieD24 (rep: 557) Jul 7, '23 at 11:00 pm
@Willie Thanks. I thought likewise but thankfully you asked for a file- that nearly always helps to clarify matters. Have a good weekend! 
John_Ru (rep: 6142) Jul 8, '23 at 1:44 am
John,  it's  perfect !
but  as  I  said I  missed thing , my  boss told  me  should print  from  the  last  highlighted cell  until  lastrow contains data  but  without  show color for  highlighted cell when print  out the paper . so in  based on attached  file  should  print out  start from row11. if  you  see I should  post  new subject I  will  do  that, sorry  about  this  confusion .
Omaran (rep: 8) Jul 8, '23 at 3:39 am
Omaran. I'm not clear on your boss's new requirement but please add another question (referring to this Answer and adding a file with a tab  showing the new desired result). I probably won't have time to help this weekend but Willie might (if not, I will respond on Monday most likely).
John_Ru (rep: 6142) Jul 8, '23 at 3:48 am
@Omaran

To include Row 11, John's code just needs a couple of small tweaaks.
First: include Row 11 (last row with highlighted cell in "E") in the print out - 
change this line
Rows("2:" & n).Hidden = True
to
Rows("2:" & n-1).Hidden = True


Second: After the line " Next n " insert the following (remove cell fill colour) -
' remove cell fill colour
Cells(n, "E").Interior.Color = xlNone


Third: restore the cell fill colour - after un-hidding the rows insert the following:
 ' restore cell fill colour
    Cells(n, "E").Interior.Color = 255

These tweaks to John's code should result in what your boss is asking for.

Cheers   :-)
WillieD24 (rep: 557) Jul 8, '23 at 9:27 am
@Willie - thanks. I reckon that would do it nicely. 
John_Ru (rep: 6142) Jul 8, '23 at 12:13 pm
@Willie 
well done !
this works  as  my boss want  it. 
thank you & John for  your assistance.
Omaran (rep: 8) Jul 9, '23 at 4:19 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login