Convert a column to a numbers that can be summed

youbitto

New Member
Joined
Jun 8, 2022
Messages
35
Office Version
  1. 2019
  2. 2016
  3. 2013
Platform
  1. Windows
Hello
I have this code that import a csv file to a worksheet and replace in the column "O" the "." with "," so I cant sum that column
however after excuting the code that column seems to be in a text format or something when I select that column it gives me the number of selected cells

My request is to covert the column "O" to number that can be summed

PS : I have a french excel that why I replace "." with ","

VBA Code:
Sub LoadCSV_FileToSheet()

Dim wsheet As Worksheet, file_mrf As String
Dim wsDestination             As Worksheet

Worksheets("listCreance").Range("A:P").Clear
Worksheets("listCreance").Range("Q5:Y99999").Clear

Set wsheet = ActiveWorkbook.Sheets("listCreance")

file_mrf = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Provide Text or CSV File:")



With wsheet.QueryTables.Add(Connection:="TEXT;" & file_mrf, Destination:=wsheet.Range("A4"))

.TextFileParseType = xlDelimited

.TextFileCommaDelimiter = True

.Refresh

End With

Columns("O").Replace What:=".", Replacement:=","


End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Change this
VBA Code:
Columns("O").Replace What:=".", Replacement:=","
as
VBA Code:
Columns("G").NumberFormat = "0,00"
Columns("O").Replace What:=".", Replacement:=","
 
Upvote 0
Change this
VBA Code:
Columns("O").Replace What:=".", Replacement:=","
as
VBA Code:
Columns("G").NumberFormat = "0,00"
Columns("O").Replace What:=".", Replacement:=","
This didn't help

what I get is in Image "1.png"
What I want in Image "2.png"
 

Attachments

  • 1.png
    1.png
    19.6 KB · Views: 10
  • 2.png
    2.png
    13.9 KB · Views: 9
Upvote 0
I found the solution
Thank you for your help

VBA Code:
Sub LoadCSV_FileToSheet()

Dim wsheet As Worksheet, file_mrf As String
Dim wsDestination             As Worksheet

Worksheets("listCreance").Range("A:P").Clear
Worksheets("listCreance").Range("Q5:Y99999").Clear

Set wsheet = ActiveWorkbook.Sheets("listCreance")

file_mrf = Application.GetOpenFilename("Text Files (*.csv),*.csv", , "Provide Text or CSV File:")



With wsheet.QueryTables.Add(Connection:="TEXT;" & file_mrf, Destination:=wsheet.Range("A4"))

.TextFileParseType = xlDelimited

.TextFileCommaDelimiter = True

.Refresh

End With


Columns("O").Replace What:=".", Replacement:=","

'Converting text to Nubmber

Dim SelectR As Range
Dim sht As Worksheet
Dim LastRow As Long

Set sht = ThisWorkbook.Sheets("listCreance")

LastRow = sht.Cells(sht.Rows.Count, "O").End(xlUp).Row

Set SelectR = ThisWorkbook.Sheets("listCreance").Range("O5:O" & LastRow)

SelectR.TextToColumns Destination:=Range("O5"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 1), TrailingMinusNumbers:=True


End Sub
 
Upvote 0
I know you have it working now but rather than add the extra conversion steps give this a try:
(added lines in blue - Remove the code you currently have below the "End With")

Rich (BB code):
With wsheet.QueryTables.Add(Connection:="TEXT;" & file_mrf, Destination:=wsheet.Range("A4"))

    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
 
    .TextFileDecimalSeparator = "."
    .TextFileThousandsSeparator = ","
 
    .Refresh

End With

' remove the code you had below here
 
Upvote 1
Solution
I know you have it working now but rather than add the extra conversion steps give this a try:
(added lines in blue - Remove the code you currently have below the "End With")

Rich (BB code):
With wsheet.QueryTables.Add(Connection:="TEXT;" & file_mrf, Destination:=wsheet.Range("A4"))

    .TextFileParseType = xlDelimited
    .TextFileCommaDelimiter = True
 
    .TextFileDecimalSeparator = "."
    .TextFileThousandsSeparator = ","
 
    .Refresh

End With

' remove the code you had below here
Oh Thank you very much, this indeed worked better and with less code
 
Upvote 0

Forum statistics

Threads
1,224,900
Messages
6,181,632
Members
453,059
Latest member
jkevin

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top