Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Hi all,
I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands |
#2
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
This might get you started.......modify as needed
Sub HighlightCharacter() With ActiveCell.Characters(Start:=3, Length:=2).Font .FontStyle = "Bold" .Size = 14 .ColorIndex = 3 End With End Sub Vaya con Dios, Chuck, CABGx3 "Jack Sons" wrote in message ... Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands |
#3
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]() You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands |
#4
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thank you Chip.
Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands |
#5
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Option Explicit
Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks Dave.
I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
#1 - not sure what you mean about "nested" Instr() limits. But I think that
the answer is no - you can nest them pretty deep in one formula, until the formula either becomes so complex that the VB engine cannot evaluate it, or until you run out of stack space. For example, you could do away with FirstPos and SecondPos entirely in Dave's code and use this (hard to decipher later) line: myCell.Characters(InStr(1, myCell.Value, vbLf, vbTextCompare) + 1, _ InStr(InStr(1, myCell.Value, vbLf, vbTextCompare) + 1, _ myCell.Value, vbLf, vbTextCompare) - _ InStr(1, myCell.Value, vbLf, vbTextCompare) - 1).Font.Bold = True If that's what you mean by nesting InStr()s For #2 - even if the cell is empty, it will not throw an error, in that case it basically sets the entire cell's format to Bold. And if there's only 1 vbLF in the middle of things, then all after that character gets set to bold. Hope that helps. "Jack Sons" wrote: Thanks Dave. I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson . |
#8
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
In xl97+, you can have almost 32k worth of characters in a cell. So it's not
unlimited. But it's pretty large! <vbg This expression looks dubious to me: myCell.Characters(21, -42).Font.Bold = ... How can I say for negative 42 characters? But excel's VBA seems to think it's ok and treats it as missing (the rest of the string will be affected). See VBA's help for characters for info. Jack Sons wrote: Thanks Dave. I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr (10) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Ignore my response about the nesting. I misread your question. You had a
question about the nesting of instr()'s. Not the number of vblf's in a cell. Dave Peterson wrote: In xl97+, you can have almost 32k worth of characters in a cell. So it's not unlimited. But it's pretty large! <vbg This expression looks dubious to me: myCell.Characters(21, -42).Font.Bold = ... How can I say for negative 42 characters? But excel's VBA seems to think it's ok and treats it as missing (the rest of the string will be affected). See VBA's help for characters for info. Jack Sons wrote: Thanks Dave. I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson -- Dave Peterson |
#10
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks for your explanation.
Jack. "JLatham" schreef in bericht ... #1 - not sure what you mean about "nested" Instr() limits. But I think that the answer is no - you can nest them pretty deep in one formula, until the formula either becomes so complex that the VB engine cannot evaluate it, or until you run out of stack space. For example, you could do away with FirstPos and SecondPos entirely in Dave's code and use this (hard to decipher later) line: myCell.Characters(InStr(1, myCell.Value, vbLf, vbTextCompare) + 1, _ InStr(InStr(1, myCell.Value, vbLf, vbTextCompare) + 1, _ myCell.Value, vbLf, vbTextCompare) - _ InStr(1, myCell.Value, vbLf, vbTextCompare) - 1).Font.Bold = True If that's what you mean by nesting InStr()s For #2 - even if the cell is empty, it will not throw an error, in that case it basically sets the entire cell's format to Bold. And if there's only 1 vbLF in the middle of things, then all after that character gets set to bold. Hope that helps. "Jack Sons" wrote: Thanks Dave. I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson . |
#11
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
Thanks again Dave.
Jack. "Dave Peterson" schreef in bericht ... Ignore my response about the nesting. I misread your question. You had a question about the nesting of instr()'s. Not the number of vblf's in a cell. Dave Peterson wrote: In xl97+, you can have almost 32k worth of characters in a cell. So it's not unlimited. But it's pretty large! <vbg This expression looks dubious to me: myCell.Characters(21, -42).Font.Bold = ... How can I say for negative 42 characters? But excel's VBA seems to think it's ok and treats it as missing (the rest of the string will be affected). See VBA's help for characters for info. Jack Sons wrote: Thanks Dave. I did my last posting at 02.05 AM, so I went to bed and saw your answer just now. Once in bed I realized that I could have explained myself much better by simply saying that I wanted to do something with the third line in the cell, but I was focused too much at the cornerstones of the third line, the chr(10)'s. These are needed of course to determine what's on that third line. Stupid that I didn't think of an InStr in an InStr. I'm sorry, too late at night I guess. Question 1: Is the number of possible "nested" InStr's unlimited? Question 2: You wrote "... if that length portion was greater than 0". Did you mean wether the third line contains any characters - other than (the third) chr(10)? Jack. "Dave Peterson" schreef in bericht ... Option Explicit Sub testme() Dim FirstPos As Long Dim SecondPos As Long Dim myCell As Range Set myCell = ActiveSheet.Range("A1") FirstPos = InStr(1, myCell.Value, vbLf, vbTextCompare) SecondPos = InStr(FirstPos + 1, myCell.Value, vbLf, vbTextCompare) myCell.Characters(FirstPos + 1, SecondPos - FirstPos - 1).Font.Bold = True End Sub Excel's VBA is pretty forgiving. It didn't even care if that length portion was greater than 0. Jack Sons wrote: Thank you Chip. Problem is, I don't know on what posititions the second chr(10) and the third chr(10) are. (with chr(10) I mean the character that causes the content to go on at a new line in the cell) Their positions vary from cell to cell in the column. The content is like xxxx...xxxchr(10)xx...xxxxchr(10)xxxxxx...xxchr(10 ) xxxx etc. The x's stand for other characters. The number of x's vary from cell to cell. In this exaple I want to do things wits the xx...xxxx part because it is between the second chr(10) and the third chr(10). What is the way to do this with code? Jack. "Chip Pearson" schreef in bericht ... You can modify static text in a cell with code like Range("A1").Characters(5, 3).Font.Bold = True This turns characters 5, 6, and 7 bold. Cordially, Chip Pearson Microsoft MVP 1998 - 2010 Pearson Software Consulting, LLC www.cpearson.com [email on web site] On Mon, 10 May 2010 00:35:18 +0200, "Jack Sons" wrote: Hi all, I want to do something (change font size and font color f.i.) with the part of the content of the active cell that is between the second and the third chr(10). What code do I need? I thank you in advance for your advice. Jack Sons The Netherlands -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
testing range of cells for part of cell content | Excel Worksheet Functions | |||
Can I use the content of a cell as part of filereference in other | Excel Worksheet Functions | |||
display part of the cell content | Excel Discussion (Misc queries) | |||
Can I search a cell for a value and extract part of content? | Excel Discussion (Misc queries) | |||
vlookup to extract part cell content | Excel Discussion (Misc queries) |