Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Retrieve variant array of cells as formatted in the cell

I often use code like the following to grab a variant array of data
containing cell data.


Sub MySub
dim rng as Range, vnt as Variant
set rng=range("A1")
vnt=rng
end Sub

However, this does not grab the data as they are seen in the cell (the
formatted text of the cell. Is there any way to grab that data without
having to use a function like the following? If not, using this
function is acceptable - i just want to know for my own knowledge.


Public Function GetCellsAsFormatted(rng As Excel.Range) As Variant
Dim i As Long, j As Long

If rng Is Nothing Then Exit Sub

ReDim GetCellsAsFormatted(1 To rng.Rows.Count, 1 To
rng.Columns.Count)
For i = LBound(GetCellsAsFormatted, 1) To
UBound(GetCellsAsFormatted, 1)
For j = LBound(GetCellsAsFormatted, 2) To
UBound(GetCellsAsFormatted, 2)
GetCellsAsFormatted(i, j) = Format(rng(i, j).Value, rng(i,
j).NumberFormat)
Next j
Next i
End Function
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Retrieve variant array of cells as formatted in the cell

No, you can't do it in your usual fashion.

You can simplify your function by using the Text property.

Public Function GetCellsAsFormatted(rng As Excel.Range) As Variant
Dim i As Long, j As Long

If rng Is Nothing Then Exit Sub

ReDim GetCellsAsFormatted(1 To rng.Rows.Count, 1 To _
rng.Columns.Count)
For i = LBound(GetCellsAsFormatted, 1) To
UBound(GetCellsAsFormatted, 1)
For j = LBound(GetCellsAsFormatted, 2) To _
UBound(GetCellsAsFormatted, 2)
GetCellsAsFormatted(i, j) = rng(i,j).Text

Next j
Next i
End Function

--
regards,
Tom Ogilvy

"R Avery" wrote in message
...
I often use code like the following to grab a variant array of data
containing cell data.


Sub MySub
dim rng as Range, vnt as Variant
set rng=range("A1")
vnt=rng
end Sub

However, this does not grab the data as they are seen in the cell (the
formatted text of the cell. Is there any way to grab that data without
having to use a function like the following? If not, using this
function is acceptable - i just want to know for my own knowledge.


Public Function GetCellsAsFormatted(rng As Excel.Range) As Variant
Dim i As Long, j As Long

If rng Is Nothing Then Exit Sub

ReDim GetCellsAsFormatted(1 To rng.Rows.Count, 1 To
rng.Columns.Count)
For i = LBound(GetCellsAsFormatted, 1) To
UBound(GetCellsAsFormatted, 1)
For j = LBound(GetCellsAsFormatted, 2) To
UBound(GetCellsAsFormatted, 2)
GetCellsAsFormatted(i, j) = Format(rng(i, j).Value, rng(i,
j).NumberFormat)
Next j
Next i
End Function



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Retrieve variant array of cells as formatted in the cell

excellent. The Text property always returns the value as formatted in
the cell. I was looking for that. Thanks.

Tom Ogilvy wrote:
No, you can't do it in your usual fashion.

You can simplify your function by using the Text property.

Public Function GetCellsAsFormatted(rng As Excel.Range) As Variant
Dim i As Long, j As Long

If rng Is Nothing Then Exit Sub

ReDim GetCellsAsFormatted(1 To rng.Rows.Count, 1 To _
rng.Columns.Count)
For i = LBound(GetCellsAsFormatted, 1) To
UBound(GetCellsAsFormatted, 1)
For j = LBound(GetCellsAsFormatted, 2) To _
UBound(GetCellsAsFormatted, 2)
GetCellsAsFormatted(i, j) = rng(i,j).Text

Next j
Next i
End Function

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
Converting 'General' formatted cells to Text formatted cell using. Zahid Khan Excel Worksheet Functions 1 March 12th 05 07:13 PM
Variant Array Steph[_3_] Excel Programming 1 June 2nd 04 01:29 AM
Best way to paste a variant array into a range? AnneB Excel Programming 2 April 28th 04 09:57 PM
variant array containing cel adresses convert to actual ranges-array Peter[_21_] Excel Programming 5 December 10th 03 09:50 PM
Reading formatted cell values into an array Tom Ogilvy Excel Programming 0 September 19th 03 06:32 PM


All times are GMT +1. The time now is 02:48 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"