PDA

View Full Version : Highlighting(Colour) cells problem in VBA excel



alihadi
08-27-2015, 11:02 AM
Hi everybody,

I would like to highlight cells in VBA code, I am attaching two excel files to show what I want, one of them includes code that I work with, and the other one includes an example that I want to achieve to highlight using VBA code.
I will be very grateful if you can assist me.

Regards
Ali

alihadi
08-27-2015, 11:28 AM
Let me give an example, when number 1 is generated in column 6 as shown the example file and number 3 is generated in column 7 with three ones in column 8, I want all these numbers to be highlighted with yellow colour with the generated numbers and times in column 9 and 10 respectively. and the same thing with the other numbers as shown in the attached files. one of the file includes the code, I want the colours to be generated with this code.

Regards
Ali

SamT
08-27-2015, 12:42 PM
All I have done so far is to format the code in your workbook. I have to go back to work now, but somebody will be along shortly.

alihadi
08-27-2015, 03:51 PM
Dear Sam,
Thanks, I have the code that can generate random numbers as shown in one of the attached files, every time you click the button numbers are generated randomly. I would like to achieve the following:
- when number (1) is generated in column (6) as shown in the example file and number 3 is generated in column 7 with three ones in column 8, I want all these numbers to be highlighted with yellow colour with the generated numbers and times in column 9 and 10 respectively. And the same thing with the other numbers as shown in the attached files. One of the file includes the code, I want the colors to be generated with this code.
I will be very grateful if you can assist me.

SamT
08-28-2015, 10:58 AM
The Colors are dependent on the values of WNM and WNA.
Please put this code in a new workbook and run it one time, then tell me the ColorIndex Numbers you want for WN1, WN2, WN3, and WN4


Sub ShowColorIndexNumbers()
With Sheet1.Columns(1)

For C = 1 to 56
With .Cells(C)
.Value = C
.Interior.ColorIndex = C
End With
Next
End With
End Sub
So if WNM or WNA = 1, and the color you want is in the cell with the number 3, then WN1 = 3
WN1 = ?
WN2 = ?
WN3 = ?
WN4 = ?

p45cal
08-28-2015, 05:35 PM
see New Button in attached.
Unfinished since it doesn't put anything in columns A:E.
Your current code regularly overwrites stuff in those columns so I'm not sure what's going on, more specifically what should be happening there.
I'll continue coding to make the routine more robust and perhaps to mimic what your code did in column A:E, but I feel it's wrong.
Your code in the file is still there, executed by its original button, but it does lots of unnecessary overwriting of cells in the other columns too, and lots of unnecessary checking for duplicates. Where did you get it?

alihadi
08-29-2015, 03:56 AM
Thank you so much p45cal for your help

alihadi
08-29-2015, 04:09 AM
Hi p45cal,
Ok, but I want the information appears in columns A:E with the highlighting the cells.

Thanks

alihadi
08-29-2015, 04:38 AM
Thanks Sam T,

WN1=Yellow
WN2= Red
WN3=Green
WN4=Orange

snb
08-29-2015, 04:58 AM
@SamT

It might be helpful to read all the threads that this OP started...

p45cal
08-29-2015, 05:08 AM
Hi p45cal,
Ok, but I want the information appears in columns A:E with the highlighting the cells.
Thanks
alihadi, again: "Your current code regularly overwrites stuff in those columns so I'm not sure what's going on, more specifically what should be happening there."

alihadi
08-29-2015, 05:20 AM
It should be exactly the same attached file. I want the information appears in those columns as in the file. when number (1) appears in (4, 6) for example, I want the information appears in (4, 1), (4, 3) & (4, 5).
Thanks

p45cal
08-29-2015, 09:56 AM
Where did you get your code?

alihadi
08-30-2015, 04:44 AM
Hi,
Did you solve the problem?

p45cal
08-30-2015, 06:33 AM
Yes. Where did you get your code?

alihadi
08-30-2015, 07:17 AM
I got the code from this forum vba express forum. If you solved the problem please let me know the solution.
Thanks

p45cal
08-30-2015, 07:26 AM
I got the code from this forum vba express forum.Could you say exactly where (provide a link) - Don't ignore. See attachment.

alihadi
08-30-2015, 11:24 AM
Thanks p45cal, would you please explain how did you solve the problem.
Thanks

alihadi
09-01-2015, 03:50 AM
Hi p45cal,
would please make the same thing with rest of the file to colour the cells. I attached the whole code.
Thanks

snb
09-01-2015, 06:19 AM
How long will this continue ?

alihadi
09-01-2015, 07:40 AM
Thanks everyone,

alihadi
09-04-2015, 09:01 AM
Hi p45cal,
I need your help in the following issue:
In the attached VBA excel file, there are two sheets the first one which is 'Collection' and the second one which is 'Max_Collection'. The Collection sheet includes the code of the model, when you run it, you will see numbers, times, letters are generated. The second one includes the maximum collection number for each company with the container size and type. What I am trying to achieve is to spread the maximum collection number in the 'Max_Collection' sheet for each company within weeks, days, and times that are generated in the 'Collection' sheet in each run. In the 'collection' sheet the weeks are generated in columns (F, M, T), the day are fixed (Mon _ Fri), the times are generated in columns (J, Q, X), and the collection numbers are generated in columns (G, N, U).
I will be very grateful if you can assist me in this issue asap please.

Thanks

alihadi
09-04-2015, 10:06 PM
Hi, I need your help please, ignor the days (Mon-Fri).
Thanks

snb
09-05-2015, 03:02 AM
also posted her:

http://www.vbaexpress.com/forum/showthread.php?53664-Numbers-generation-problem-using-VBA-code-in-excel&p=330318&viewfull=1#post330318

alihadi
09-05-2015, 02:32 PM
Please,I need your help asap
Thanks

alihadi
09-06-2015, 01:09 AM
Dear snb,
I need your help in the following issue:
In the attached VBA excel file, there are two sheets the first one which is 'Collection' and the second one which is 'Max_Collection'. The Collection sheet includes the code of the model, when you run it, you will see numbers, times, letters are generated. The second one includes the maximum collection number for each company with the container size and type. What I am trying to achieve is to spread the maximum collection number in the 'Max_Collection' sheet for each company within weeks, days, and times that are generated in the 'Collection' sheet in each run. In the 'collection' sheet the weeks are generated in columns (F, M, T), serial numbers are generated in columns (I, P, W), the times are generated in columns (J, Q, X), and the collection numbers are generated in columns (G, N, U).
I will be very grateful if you can assist me in this issue asap please.

Thanks

snb
09-06-2015, 06:28 AM
ASAP isn't cheap: what is your budget available ?

alihadi
09-06-2015, 12:28 PM
What do you mean by budget? I said I need your help.