Hi,
I'm sorry for english.
I will tell you that picture.
If you know how to write macros;
There to help.
Thank you very much.
ck521hqwmqnzvvo63.gif
Hi,
I'm sorry for english.
I will tell you that picture.
If you know how to write macros;
There to help.
Thank you very much.
ck521hqwmqnzvvo63.gif
Instead of picture please attach a sample workbook with enough data to make it clear what is needed. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are demonstrated, mock them up manually if needed. Remember to desensitize the data.
Click on GO ADVANCED and use the paperclip icon to open the upload window.
View Pic
If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
Mark your thread as Solved
If the suggestion helps you, then Click *below to Add Reputation
Hi,Sixthsense
![]()
How to install your new code
- Copy the Excel VBA code
- Select the workbook in which you want to store the Excel VBA code
- Press Alt+F11 to open the Visual Basic Editor
- Choose Insert > Module
- Edit > Paste the macro into the module that appeared
- Close the VBEditor
- Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)
=GetMax(Range,ColorNum)![]()
Function GetMax(rMyRng As Range, iColor As Integer) As Long Dim r As Range, lTemp As Long, lMax As Long Application.Volatile True For Each r In rMyRng If r.Font.ColorIndex = iColor Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If Next r GetMax = lMax End Function
=GetMax(E2:K2,3)
Hi, Sixthsense
You worked very hard.
A big thank you for that.
There are also data on this page. And they should be exempted.
To do this, your code. Buttons should work with.
Results area will be written: (B2: B. .....)
Where the area to be checked: (E2: K. ....)
I hope. It was understandable.
summary:
Macro should work with the button.
Work areas should be interfered with.
(B2: B. ...) and (E2: K. ....)
Last edited by pixel34; 12-16-2013 at 03:19 AM.
Sorry I am unable to understand your further requirement which you posted in Post #5
You can adjust the range and use the UDF formula at anywhere in the workbook.
Example;
Sub Macro()
'..............
'..............
End Sub
I am ready to convert the UDF to macro but before that I just want to know what is the draw back having it in UDF?
Becuase I believe UDF is more flexible than the Macro code in this case.
I'm so sorry.
destroy your valuable time.
Whether your macro works as follows.
(B2: last line) and (E2: K last line)
And you're working with a macro button.
Before I forget. Greetings from Anatolia to India.![]()
Try this code…
![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Font.ColorIndex = 3 Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If Next r Cells(i, "B").Value = lMax lMax = 0 Next i End Sub
Try
![]()
Sub test() Dim i As Long, r As Range With Range("e2:k9") For i = 1 To .Rows.Count .Cells(i, -2).Value = GetMaxColor(.Rows(i)) Next End With End Sub Function GetMaxColor(rng As Range) As Long Dim r As Range, n As Long, temp Application.Volatile For Each r In rng.Cells If (r.Font.ColorIndex <> xlAutomatic) * (r.Value <> "") Then If temp <> r.Font.Color Then n = 1: temp = r.Font.Color GetMaxColor = Application.Max(GetMaxColor, n) Else n = n + 1 GetMaxColor = Application.Max(GetMaxColor, n) End If Else temp = 0 End If Next End Function
Hi, Sixthsense
ultra super
Thank you friend.
With the same logic.
Red was the color of column B
Whether black colors column A
possible?
To know the Number of the Font Color just place the cursor on that cell and Press Alt+F11 and Press Ctrl+G and copy paste the below code and hit enter.
?Activecell.Font.ColorIndex
Which will get you the color of the font (In which the cursor is placed)
In the below line of the provided code just replace the 3 (3 for red) to 1 (1 for black) with the number arrived in immediate window.
![]()
If r.Font.ColorIndex = 3 Then
Dear Jindon;
Your code is beautiful.
No errors. Doing the correct procedure.
Getting the desired results.
But the code is not fully understood.
Whether you like the following macro style.
![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Font.ColorIndex = 3 Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If Next r Cells(i, "B").Value = lMax lMax = 0 Next i End Sub
@ pixel34,
If jindon's code gets the desired result then please stick with it for fine tuning
Because I don't want both of us (Me and Jindon) to spend much more time for this one unnecessarily. You may be enjoying the varieties but from my point of view your requirement is getting growing for each post of this thread when comparing to your initial thread![]()
hi, jindon
great code
I wanted a little more detail would be?
Excuse me Sixthsense
If the cell is empty, jump in your code should be
Value <> "" Then
Oops... try try the below code for getting result for both Column-A (For Black Color Text) and Column-B (For Red Color Text)
![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range, x As Byte, sCol As String lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For x = 1 To 2 sCol = "A": iColor = -4105 'For Black If x = 2 Then sCol = "B": iColor = 3 'For Black For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Font.ColorIndex = iColor Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If Next r Cells(i, sCol).Value = lMax lTemp = 0 lMax = 0 Next i Next x End Sub
Dear Sixthsense,
I did the wrong test.
The first summer of the year, even if the macros incorrect.
if you don;
E: K is red all data from
value of "0" is doing.
Yet the value "7" will be.
It also handles empty cells will take.
(Empty cells will be traded.)
(Skip empty cells)
This macro message: 11
![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Font.ColorIndex = 3 Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If Next r Cells(i, "B").Value = lMax lMax = 0 Next i End Sub
Last edited by pixel34; 12-16-2013 at 04:39 AM.
Try this...
![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range, x As Byte, sCol As String lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For x = 1 To 2 sCol = "A": iColor = -4105 'For Black If x = 2 Then sCol = "B": iColor = 3 'For Black For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Value <> "" Then If r.Font.ColorIndex = iColor Then lTemp = lTemp + 1 Else If lTemp > lMax Then lMax = lTemp lTemp = 0 End If End If Next r Cells(i, sCol).Value = lMax lTemp = 0 lMax = 0 Next i Next x End Sub
I am sorry. Dear Sixthsense
But still wrong.
What's wrong? I showed in the example.
What I understand is count the max consecutive font color except the cell with no value and font colorindex = default color.(xlAutomatic)
So it will count consecutive any font color.
Completely different in logic from the other code.
Dear Sixthsense
It is a good alternative.
Alternative to happen to?![]()
The code is specially designed to what you have uploaded.
change
to![]()
With Range("e2:k9")
Then selection the cells to be calculated and run the code.![]()
With Selection
However the selection should start from Col.D as least.
If you run the code with the selection includes Col.A-C. it will give you the error.
You know, I don't like to write a code with GUESS....
This is a great code.
Dear Sixthsense
I'm doing the following experiment.
Last edited by pixel34; 12-16-2013 at 07:04 AM.
Glad it helps you and thanks for the feedback![]()
I'm really grateful to you.
Dear Jindon.
I think it's code @Sixthsense more valuable for me.
Error correction of hope.
Dear Sixthsense.
You misunderstand me. I felt.
I can not write in English.
These articles are reaching you with google translate.
If there is a mistake I'm sorry.
I you, I'm waiting for answers to 21 numbers of the posts.
If you do not answer, please'll be off topic.
I can not use code Jindon.
Try this final version of code...
Refer the attached file for details. If it gets any wrong results then please highlight those rows with expected result![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range, x As Byte, sCol As String lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For x = 1 To 2 sCol = "A": iColor = -4105 'For Black If x = 2 Then sCol = "B": iColor = 3 'For Black For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Value <> "" Then If r.Font.ColorIndex = iColor Then lTemp = lTemp + 1 Else lTemp = 0 End If Else lTemp = 0 End If If lTemp > lMax Then lMax = lTemp Next r Cells(i, sCol).Value = lMax lTemp = 0 lMax = 0 Next i Next x End Sub
![]()
Dear Sixthsense;
21 of the posts I did try the example files in the attachment.
12 lines A12 cell value "0" is not
"1" should be. Because the data in this row are black.
21 of the message with the attached excel
please do the experiment.
Please attach a file with code and highlight the wrong result with expected answer![]()
Example is ready.
dear Sixthsense
Try this revised code...
Refer the attached file for details![]()
Sub GetMax() Dim iColor As Integer, lTemp As Long, lMax As Long, lEndRw As Long, i As Long Dim rMyRng As Range, r As Range, x As Byte, sCol As String lEndRw = Cells(Rows.Count, "E").End(xlUp).Row Set rMyRng = Range("E1:K" & lEndRw) For x = 1 To 2 sCol = "A": iColor = 0 'For Black If x = 2 Then sCol = "B": iColor = 255 'For Black For i = 2 To lEndRw For Each r In rMyRng.Rows(i).Cells If r.Value <> "" Then If r.Font.Color = iColor Then lTemp = lTemp + 1 Else lTemp = 0 End If Else lTemp = 0 End If If lTemp > lMax Then lMax = lTemp Next r Cells(i, sCol).Value = lMax lTemp = 0 lMax = 0 Next i Next x End Sub
![]()
Yuuuuuuuuuppiiiiiiiiiiiiiiiiiiiii
You're a great Sixthsense.
Topic is solved.
Please get marked.
I can not.
You're Welcome
If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.
I did it.
Thank you again.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks