Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default YYY-MM-DD format is changing when convert data to Flat File


Hi ,
i am converting the worksheet data into a text file using some decimeter
using the following code. But the data format of YYYY-MM-DD value is
converting wrong in the text file. Please find the value i am using and my
code for converting to the text file.

***********
Base_Date: 2009-03-30
it is populating as "Base_Date;39902" in text file.
***********
Code
*******

Public Function AppendData(fileName As String)

Dim ts As TextStream
Dim fileContent As String, delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long, pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim fso As FileSystemObject

ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
columnCount = GetColumnCount
pageNumber = 1
pageSize = MAX_CONCAT_COL
delimiter = GetDelimiter(ActiveSheet.CodeName)
Do While (pageNumber - 1) * pageSize < columnCount
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunction(delimiter, pageNumber,
pageSize, columnCount)
End With

' Calling ConcatFunctionRow function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunctionRow(delimiter, pageNumber,
pageSize, columnCount)
End With

pageNumber = pageNumber + 1
Loop

If pageNumber 2 Then
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

' Calling MasterConcatFunction function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

dataColumn = pageNumber
Else
dataColumn = 1
End If

rowCount = GetRowCount

If rowCount 2 Then
Range(ActiveWorkbook.Worksheets("Anvil").Cells(2, 1), _
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount,
dataColumn)).FillDown
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(fileName, ForWriting, True)
With Range(ActiveWorkbook.Worksheets("Anvil").Cells(1, dataColumn), _
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount, dataColumn))
For Each tempCell In .Cells

If tempCell.Row < rowCount Then
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
If tempCell.Value < "Flat_File_Field_Delimiter;;" Then
Call ts.WriteLine(tempCell.Value)
End If
Else
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
Call ts.Write(tempCell.Value)
End If
Next
End With
ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
ts.Close
Exit Function
End Function

Public Function ConcatFunction(delimiter As String, pageNumber As Integer, _
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

'incorporated the dynamic value of the delimiter
For index = startIndex To endIndex
concatString = concatString & " '" & Replace(sheetName, "'", "''") & _
"'!RC[" & index & "] & """ & delimiter & """"
If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunction = concatString
End Function

'added a new function to cater to all the rows(other than the header)
concatentaion
Public Function ConcatFunctionRow(delimiter As String, pageNumber As
Integer, _
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String, temp As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

For index = startIndex To endIndex

temp = Sheets(sheetName).Cells(2, index + pageNumber).NumberFormat

'For bug 5402115
If temp = "@" Then
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",'" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]) & """ & delimiter & """"
Else
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",text('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "],""" & temp & """)) & """ & delimiter &
""""
End If

If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunctionRow = concatString
End Function

Sub Cancel_Click()
ActiveWorkbook.Names("CurrentTag").RefersToRange.V alue = ""
End Sub


Public Function GetColumnCount() As Integer
Dim tempRange As Range

If ActiveSheet.Range("A1").Value = "" Then
GetColumnCount = 0
Else
GetColumnCount = _

ActiveSheet.Range("A1").End(xlToRight).End(xlToRig ht).End(xlToLeft).Column
End If

End Function

Public Function GetRowCount() As Long
GetRowCount = ActiveSheet.UsedRange.Rows.Count
End Function


Public Function MasterConcatFunction(pageCount As Integer) As String
Dim index As Integer
Dim concatString As String

concatString = "="
For index = pageCount To 1 Step -1
concatString = concatString & " RC[-" & index & "]"
If index 1 Then concatString = concatString & " & "
Next

MasterConcatFunction = concatString
End Function





  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default YYY-MM-DD format is changing when convert data to Flat File


you need to tell us what you mean by "converting wrong" and some idea of
what you have and what you expect

As far as i can see the code you sent formats everything as "general"... i
see no date formatting anywhere... so any dates in the sheet will have been
either text or shown as their raw number - ie days since 30-dec-1899 --- and
this is how they would be expoerted


"Bobby" wrote in message
...
Hi ,
i am converting the worksheet data into a text file using some decimeter
using the following code. But the data format of YYYY-MM-DD value is
converting wrong in the text file. Please find the value i am using and my
code for converting to the text file.

***********
Base_Date: 2009-03-30
it is populating as "Base_Date;39902" in text file.
***********
Code
*******

Public Function AppendData(fileName As String)

Dim ts As TextStream
Dim fileContent As String, delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long, pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim fso As FileSystemObject

ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
columnCount = GetColumnCount
pageNumber = 1
pageSize = MAX_CONCAT_COL
delimiter = GetDelimiter(ActiveSheet.CodeName)
Do While (pageNumber - 1) * pageSize < columnCount
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunction(delimiter, pageNumber,
pageSize, columnCount)
End With

' Calling ConcatFunctionRow function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunctionRow(delimiter, pageNumber,
pageSize, columnCount)
End With

pageNumber = pageNumber + 1
Loop

If pageNumber 2 Then
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

' Calling MasterConcatFunction function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

dataColumn = pageNumber
Else
dataColumn = 1
End If

rowCount = GetRowCount

If rowCount 2 Then
Range(ActiveWorkbook.Worksheets("Anvil").Cells(2, 1), _
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount,
dataColumn)).FillDown
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(fileName, ForWriting, True)
With Range(ActiveWorkbook.Worksheets("Anvil").Cells(1, dataColumn),
_
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount, dataColumn))
For Each tempCell In .Cells

If tempCell.Row < rowCount Then
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
If tempCell.Value < "Flat_File_Field_Delimiter;;" Then
Call ts.WriteLine(tempCell.Value)
End If
Else
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
Call ts.Write(tempCell.Value)
End If
Next
End With
ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
ts.Close
Exit Function
End Function

Public Function ConcatFunction(delimiter As String, pageNumber As Integer,
_
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

'incorporated the dynamic value of the delimiter
For index = startIndex To endIndex
concatString = concatString & " '" & Replace(sheetName, "'", "''")
& _
"'!RC[" & index & "] & """ & delimiter & """"
If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunction = concatString
End Function

'added a new function to cater to all the rows(other than the header)
concatentaion
Public Function ConcatFunctionRow(delimiter As String, pageNumber As
Integer, _
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String, temp As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

For index = startIndex To endIndex

temp = Sheets(sheetName).Cells(2, index + pageNumber).NumberFormat

'For bug 5402115
If temp = "@" Then
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",'" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]) & """ & delimiter & """"
Else
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",text('" & Replace(sheetName,
"'",
"''") & _
"'!RC[" & index & "],""" & temp & """)) & """ & delimiter &
""""
End If

If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunctionRow = concatString
End Function

Sub Cancel_Click()
ActiveWorkbook.Names("CurrentTag").RefersToRange.V alue = ""
End Sub


Public Function GetColumnCount() As Integer
Dim tempRange As Range

If ActiveSheet.Range("A1").Value = "" Then
GetColumnCount = 0
Else
GetColumnCount = _

ActiveSheet.Range("A1").End(xlToRight).End(xlToRig ht).End(xlToLeft).Column
End If

End Function

Public Function GetRowCount() As Long
GetRowCount = ActiveSheet.UsedRange.Rows.Count
End Function


Public Function MasterConcatFunction(pageCount As Integer) As String
Dim index As Integer
Dim concatString As String

concatString = "="
For index = pageCount To 1 Step -1
concatString = concatString & " RC[-" & index & "]"
If index 1 Then concatString = concatString & " & "
Next

MasterConcatFunction = concatString
End Function





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 75
Default YYY-MM-DD format is changing when convert data to Flat File


Hi Patrick,

Iam giving the date in my worksheet as 2009-03-30 and it is converting in
text file as "39902".

Thnaks,
Bobby

"Patrick Molloy" wrote:

you need to tell us what you mean by "converting wrong" and some idea of
what you have and what you expect

As far as i can see the code you sent formats everything as "general"... i
see no date formatting anywhere... so any dates in the sheet will have been
either text or shown as their raw number - ie days since 30-dec-1899 --- and
this is how they would be expoerted


"Bobby" wrote in message
...
Hi ,
i am converting the worksheet data into a text file using some decimeter
using the following code. But the data format of YYYY-MM-DD value is
converting wrong in the text file. Please find the value i am using and my
code for converting to the text file.

***********
Base_Date: 2009-03-30
it is populating as "Base_Date;39902" in text file.
***********
Code
*******

Public Function AppendData(fileName As String)

Dim ts As TextStream
Dim fileContent As String, delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long, pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim fso As FileSystemObject

ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
columnCount = GetColumnCount
pageNumber = 1
pageSize = MAX_CONCAT_COL
delimiter = GetDelimiter(ActiveSheet.CodeName)
Do While (pageNumber - 1) * pageSize < columnCount
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunction(delimiter, pageNumber,
pageSize, columnCount)
End With

' Calling ConcatFunctionRow function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunctionRow(delimiter, pageNumber,
pageSize, columnCount)
End With

pageNumber = pageNumber + 1
Loop

If pageNumber 2 Then
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

' Calling MasterConcatFunction function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

dataColumn = pageNumber
Else
dataColumn = 1
End If

rowCount = GetRowCount

If rowCount 2 Then
Range(ActiveWorkbook.Worksheets("Anvil").Cells(2, 1), _
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount,
dataColumn)).FillDown
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(fileName, ForWriting, True)
With Range(ActiveWorkbook.Worksheets("Anvil").Cells(1, dataColumn),
_
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount, dataColumn))
For Each tempCell In .Cells

If tempCell.Row < rowCount Then
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
If tempCell.Value < "Flat_File_Field_Delimiter;;" Then
Call ts.WriteLine(tempCell.Value)
End If
Else
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
Call ts.Write(tempCell.Value)
End If
Next
End With
ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
ts.Close
Exit Function
End Function

Public Function ConcatFunction(delimiter As String, pageNumber As Integer,
_
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

'incorporated the dynamic value of the delimiter
For index = startIndex To endIndex
concatString = concatString & " '" & Replace(sheetName, "'", "''")
& _
"'!RC[" & index & "] & """ & delimiter & """"
If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunction = concatString
End Function

'added a new function to cater to all the rows(other than the header)
concatentaion
Public Function ConcatFunctionRow(delimiter As String, pageNumber As
Integer, _
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String, temp As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

For index = startIndex To endIndex

temp = Sheets(sheetName).Cells(2, index + pageNumber).NumberFormat

'For bug 5402115
If temp = "@" Then
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",'" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]) & """ & delimiter & """"
Else
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",text('" & Replace(sheetName,
"'",
"''") & _
"'!RC[" & index & "],""" & temp & """)) & """ & delimiter &
""""
End If

If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunctionRow = concatString
End Function

Sub Cancel_Click()
ActiveWorkbook.Names("CurrentTag").RefersToRange.V alue = ""
End Sub


Public Function GetColumnCount() As Integer
Dim tempRange As Range

If ActiveSheet.Range("A1").Value = "" Then
GetColumnCount = 0
Else
GetColumnCount = _

ActiveSheet.Range("A1").End(xlToRight).End(xlToRig ht).End(xlToLeft).Column
End If

End Function

Public Function GetRowCount() As Long
GetRowCount = ActiveSheet.UsedRange.Rows.Count
End Function


Public Function MasterConcatFunction(pageCount As Integer) As String
Dim index As Integer
Dim concatString As String

concatString = "="
For index = pageCount To 1 Step -1
concatString = concatString & " RC[-" & index & "]"
If index 1 Then concatString = concatString & " & "
Next

MasterConcatFunction = concatString
End Function





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default YYY-MM-DD format is changing when convert data to Flat File


the date you "see" in a cell is the formatted view. the value in the cell is
actually 39902 , which is the number of days since 30/12/1899
your code sets the format of all cells to "general" and this is causing the
problem

if you know that a column or range is dates, then after you set the overall
format tto general, you must format the dates back as date

so add a line like this
Range("B:B").NumberFormat = "YYYY-MMM-DD"
for a whole column, or like this
Range("B7:D15").NumberFormat = "YYYY-MMM-DD"
for a range


"Bobby" wrote in message
...
Hi Patrick,

Iam giving the date in my worksheet as 2009-03-30 and it is converting in
text file as "39902".

Thnaks,
Bobby

"Patrick Molloy" wrote:

you need to tell us what you mean by "converting wrong" and some idea of
what you have and what you expect

As far as i can see the code you sent formats everything as "general"...
i
see no date formatting anywhere... so any dates in the sheet will have
been
either text or shown as their raw number - ie days since 30-dec-1899 ---
and
this is how they would be expoerted


"Bobby" wrote in message
...
Hi ,
i am converting the worksheet data into a text file using some
decimeter
using the following code. But the data format of YYYY-MM-DD value is
converting wrong in the text file. Please find the value i am using and
my
code for converting to the text file.

***********
Base_Date: 2009-03-30
it is populating as "Base_Date;39902" in text file.
***********
Code
*******

Public Function AppendData(fileName As String)

Dim ts As TextStream
Dim fileContent As String, delimiter As String
Dim rowCount As Long, columnCount As Long, dataColumn As Long,
pageSize
As Long
Dim pageNumber As Integer
Dim tempRange As Range, tempCell As Range
Dim fso As FileSystemObject

ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
columnCount = GetColumnCount
pageNumber = 1
pageSize = MAX_CONCAT_COL
delimiter = GetDelimiter(ActiveSheet.CodeName)
Do While (pageNumber - 1) * pageSize < columnCount
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunction(delimiter, pageNumber,
pageSize, columnCount)
End With

' Calling ConcatFunctionRow function for rows other than the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = ConcatFunctionRow(delimiter, pageNumber,
pageSize, columnCount)
End With

pageNumber = pageNumber + 1
Loop

If pageNumber 2 Then
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(1,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

' Calling MasterConcatFunction function for rows other than
the
header
Set tempRange = ActiveWorkbook.Worksheets("Anvil").Cells(2,
pageNumber)
With tempRange
.NumberFormat = "General"
.FormulaR1C1 = MasterConcatFunction(pageNumber - 1)
End With

dataColumn = pageNumber
Else
dataColumn = 1
End If

rowCount = GetRowCount

If rowCount 2 Then
Range(ActiveWorkbook.Worksheets("Anvil").Cells(2, 1), _
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount,
dataColumn)).FillDown
End If

Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(fileName, ForWriting, True)
With Range(ActiveWorkbook.Worksheets("Anvil").Cells(1,
dataColumn),
_
ActiveWorkbook.Worksheets("Anvil").Cells(rowCount,
dataColumn))
For Each tempCell In .Cells

If tempCell.Row < rowCount Then
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
If tempCell.Value < "Flat_File_Field_Delimiter;;"
Then
Call ts.WriteLine(tempCell.Value)
End If
Else
tempCell.Value = Left(tempCell.Value,
Len(tempCell.Value) - 1)
Call ts.Write(tempCell.Value)
End If
Next
End With
ActiveWorkbook.Worksheets("Anvil").Cells.ClearCont ents
ts.Close
Exit Function
End Function

Public Function ConcatFunction(delimiter As String, pageNumber As
Integer,
_
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

'incorporated the dynamic value of the delimiter
For index = startIndex To endIndex
concatString = concatString & " '" & Replace(sheetName, "'",
"''")
& _
"'!RC[" & index & "] & """ & delimiter & """"
If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunction = concatString
End Function

'added a new function to cater to all the rows(other than the header)
concatentaion
Public Function ConcatFunctionRow(delimiter As String, pageNumber As
Integer, _
pageSize As Long, columnCount As Long) As String
Dim index As Integer, startIndex As Integer, endIndex As Integer
Dim concatString As String, sheetName As String, temp As String

sheetName = ActiveSheet.Name
concatString = "="
startIndex = (pageNumber - 1) * pageSize + 1 - pageNumber
endIndex = IIf(columnCount < pageNumber * pageSize, _
columnCount - pageNumber, pageNumber * (pageSize - 1))

For index = startIndex To endIndex

temp = Sheets(sheetName).Cells(2, index +
pageNumber).NumberFormat

'For bug 5402115
If temp = "@" Then
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",'" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]) & """ & delimiter & """"
Else
concatString = concatString & " IF('" & Replace(sheetName, "'",
"''") & _
"'!RC[" & index & "]="""","""",text('" & Replace(sheetName,
"'",
"''") & _
"'!RC[" & index & "],""" & temp & """)) & """ &
delimiter &
""""
End If

If index < endIndex Then concatString = concatString & " & "
Next

ConcatFunctionRow = concatString
End Function

Sub Cancel_Click()
ActiveWorkbook.Names("CurrentTag").RefersToRange.V alue = ""
End Sub


Public Function GetColumnCount() As Integer
Dim tempRange As Range

If ActiveSheet.Range("A1").Value = "" Then
GetColumnCount = 0
Else
GetColumnCount = _

ActiveSheet.Range("A1").End(xlToRight).End(xlToRig ht).End(xlToLeft).Column
End If

End Function

Public Function GetRowCount() As Long
GetRowCount = ActiveSheet.UsedRange.Rows.Count
End Function


Public Function MasterConcatFunction(pageCount As Integer) As String
Dim index As Integer
Dim concatString As String

concatString = "="
For index = pageCount To 1 Step -1
concatString = concatString & " RC[-" & index & "]"
If index 1 Then concatString = concatString & " & "
Next

MasterConcatFunction = concatString
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
convert matrix to flat file format Felix Excel Discussion (Misc queries) 1 November 29th 07 02:11 PM
Repeated data into flat file format Paul Simon Excel Worksheet Functions 4 July 9th 06 04:33 AM
How to convert a Pivot Table into a Flat File format? [email protected] Excel Discussion (Misc queries) 1 February 22nd 06 05:17 PM
how do I convert an excel file to a flat text file Lannutslp Excel Discussion (Misc queries) 1 June 3rd 05 10:17 AM
Convert excel file to flat text file Lannutslp Excel Discussion (Misc queries) 1 June 1st 05 03:48 AM


All times are GMT +1. The time now is 01:19 AM.

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"