Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Grab Parents?

Hi guys.

I am trying to write a method to take a range of cells, and write them
into a 'list cell' in the following format:
=E6 & CHAR(10)& G4 & CHAR(10) & K22
for exmample. (CHAR(10) is the newline character in Excel btw.)

I am using an inputbox to select the desired cells to append to the
list cell.
I have got as far as selecting them, but have no idea how to add them
in this way. Any ideas?

Public Sub AddParents()
Dim parents As Range
Dim parent As Range
Dim currParents As Range

Set parents = Application.InputBox("Select a range", Type:=8)
If Not parents Is Nothing Then
Set currParents = ActiveCell
For Each parent In parents
If Not InRange(parent, currParents) Then
'add parent to currParents in the above format
End If
Next parent
End If

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Grab Parents?

One way:

First - "parent" is a reserved word in VBA. It's best not to use it -
VBA won't be confused, but those trying to maintain your code might be.

Public Sub AddParents()
#If Mac Then
Const sSEPARATOR As String = "&CHAR(13)&"
#Else
Const sSEPARATOR As String = "&CHAR(10)& "
#End If
Dim rParents As Range
Dim rParent As Range
Dim sFormula As String

Set rParents = Application.InputBox("Select a range", Type:=8)
If Not rParents Is Nothing Then
sFormula = "=" & ActiveCell.Text & sSEPARATOR
For Each rParent In rParents
If Intersect(rParent, ActiveCell) Is Nothing Then _
sFormula = sFormula & rParent.Text & sSEPARATOR
Next rParent
ActiveCell.Formula = Left(sFormula, Len(sFormula) - _
Len(sSEPARATOR))
End If
End Sub


In article . com,
"Kidaz" wrote:

Hi guys.

I am trying to write a method to take a range of cells, and write them
into a 'list cell' in the following format:
=E6 & CHAR(10)& G4 & CHAR(10) & K22
for exmample. (CHAR(10) is the newline character in Excel btw.)

I am using an inputbox to select the desired cells to append to the
list cell.
I have got as far as selecting them, but have no idea how to add them
in this way. Any ideas?

Public Sub AddParents()
Dim parents As Range
Dim parent As Range
Dim currParents As Range

Set parents = Application.InputBox("Select a range", Type:=8)
If Not parents Is Nothing Then
Set currParents = ActiveCell
For Each parent In parents
If Not InRange(parent, currParents) Then
'add parent to currParents in the above format
End If
Next parent
End If

End Sub

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
number grab David New Users to Excel 5 July 20th 06 10:45 PM
grab detail when = 1 jenn Excel Worksheet Functions 0 January 12th 06 09:06 PM
Grab name of folder scantor145[_13_] Excel Programming 1 July 1st 05 01:17 PM
First Letters Grab Pitbull Excel Discussion (Misc queries) 6 January 6th 05 01:51 PM
Grab Password Name Paul P[_3_] Excel Programming 3 October 24th 03 01:07 AM


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

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

About Us

"It's about Microsoft Excel"