Hi all,
I have built a spreadsheet that imports data from a CSV file and then applies some formulas to do some calculations on the newly imported data. I built the spreadsheet on a Mac and then moved it over to a PC. The macro scripts work perfectly on the Mac, but I get an error when I run them on the PC.
The error comes from the fact that the imported data is not recognised as a number and therefore it cannot complete the calculations in the sum. Things that makes this weird:
Has anyone had anything like this before? Any ideas as to how I can fix it? Need to get this working on both the Mac and PC versions.
I have included the code for the formatting below which is executing, but applying the formatting to the defined columns.
Thanks in advance
I have built a spreadsheet that imports data from a CSV file and then applies some formulas to do some calculations on the newly imported data. I built the spreadsheet on a Mac and then moved it over to a PC. The macro scripts work perfectly on the Mac, but I get an error when I run them on the PC.
The error comes from the fact that the imported data is not recognised as a number and therefore it cannot complete the calculations in the sum. Things that makes this weird:
- I have an initial script that converts text to a number based on the csv file import.
- I then have a formatting script that applies an accountancy format to the columns in question.
- Finally, I have a calculation script that performs the calculation.
Has anyone had anything like this before? Any ideas as to how I can fix it? Need to get this working on both the Mac and PC versions.
I have included the code for the formatting below which is executing, but applying the formatting to the defined columns.
Thanks in advance
VBA Code:
Sub Format()
Dim wsBet_Data As Worksheet
Dim dataRange As Range
Dim colG As Range, colJ As Range, colP As Range
Dim colK As Range
Dim lastRow As Long
Dim cell As Range
' Set the worksheet
Set wsBet_Data = ThisWorkbook.Sheets("Bet_Data")
' Determine the last row with data in column A (assuming A has data in all rows)
lastRow = wsBet_Data.Cells(wsBet_Data.Rows.Count, 1).End(xlUp).Row
' Convert text in G, J, and P to numbers
Set colG = wsBet_Data.Range("G2:G" & lastRow)
Set colJ = wsBet_Data.Range("J2:J" & lastRow)
Set colP = wsBet_Data.Range("P2:P" & lastRow)
Set colK = wsBet_Data.Range("K2:K" & lastRow)
For Each cell In colG
If IsNumeric(cell.Value) Then
cell.Value = cell.Value * 1 ' Convert text to number
End If
Next cell
For Each cell In colJ
If IsNumeric(cell.Value) Then
cell.Value = cell.Value * 1
End If
Next cell
For Each cell In colP
If IsNumeric(cell.Value) Then
cell.Value = cell.Value * 1
End If
Next cell
' Apply accounting formatting with £ symbol to column AF and other columns
colG.NumberFormat = "_(* £* #,##0.00_);_(* £* \(#,##0.00\);_(* £* ""-""_);_(@_)"
colJ.NumberFormat = "_(* £* #,##0.00_);_(* £* \(#,##0.00\);_(* £* ""-""_);_(@_)"
colP.NumberFormat = "_(* £* #,##0.00_);_(* £* \(#,##0.00\);_(* £* ""-""_);_(@_)"
' Convert column K to dates and apply UK date formatting
Set colK = wsBet_Data.Range("K2:K" & lastRow)
For Each cell In colK
If IsDate(cell.Value) Or IsNumeric(cell.Value) Then
cell.Value = CDate(cell.Value) ' Convert text to date
End If
Next cell
Set colK = wsBet_Data.Range("K2:K" & lastRow)
For Each cell In colK
If IsDate(cell.Value) Then
cell.Value = Int(cell.Value) ' Remove the time portion
cell.NumberFormat = "dd/mm/yyyy" ' Format as UK date
End If
Next cell
End Sub
Last edited by a moderator: