Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA part of cell content

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   Report Post  
Posted to microsoft.public.excel.misc
CLR CLR is offline
external usenet poster
 
Posts: 594
Default VBA part of cell content

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default VBA part of cell content


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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA part of cell content

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 420
Default VBA part of cell content

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 144
Default VBA part of cell content

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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default VBA part of cell content

#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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 420
Default VBA part of cell content

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
testing range of cells for part of cell content Daniel Excel Worksheet Functions 5 March 25th 10 08:14 PM
Can I use the content of a cell as part of filereference in other Excelhobbyist Excel Worksheet Functions 5 December 30th 08 02:44 PM
display part of the cell content linda Excel Discussion (Misc queries) 4 August 28th 07 03:02 AM
Can I search a cell for a value and extract part of content? Leben Excel Discussion (Misc queries) 1 December 16th 05 09:43 AM
vlookup to extract part cell content excelFan Excel Discussion (Misc queries) 2 December 5th 04 08:45 AM


All times are GMT +1. The time now is 09:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"