Run Time error 1004

schniggeldorf

New Member
Joined
Jun 30, 2017
Messages
2
Hi:

I am trying to write vba code that checks each used cell in a specific worksheet and changes its format to numeric, with zero decimal places. However, I want the code to skip the contents of 3 columns, as these contain dates or strings.

My code is as follows:
Code:
With ThisWorkbook.Worksheets("KpData")
        For Each cell In .UsedRange            If cell.Row <> 1 Then
                Debug.Print "Before: " & cell.Address, cell.NUMBERFORMAT
                ColLetter = ConvertToLetter(cell.Column)
                HeaderValue = Range(ColLetter & "1").Value
                If cell.Value = "NULL" Then
                    cell.ClearContents
                    cell.ClearFormats
                ElseIf HeaderValue <> "EncounterDate" And HeaderValue <> "ADM_Date" And HeaderValue <> "Prefix" Then
                    cell.NUMBERFORMAT = "0" 'This converts it to a number format.
                End If
            End If
            Debug.Print "After: " & cell.Address, cell.NUMBERFORMAT
        Next cell
End With

The code runs fine, until it gets to cell BA2, when it gives me a run time error 1004. I've tried using it to process several different spreadsheets, and regardless of what data are in the worksheets, it always bails at BA2. (The last used column in each worksheet is EX.)

I've searched the web for this error, but nobody else's situation seems parallel to mine.

Can anybody offer ideas? Thanks.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Here it is:

Code:
Public Function ConvertToLetter(iCol As Integer) As StringDim iAlpha As Integer
Dim iRemainder As Integer
   iAlpha = Int(iCol / 27)
   iRemainder = iCol - (iAlpha * 26)
   If iAlpha > 0 Then
      ConvertToLetter = Chr(iAlpha + 64)
   End If
   If iRemainder > 0 Then
      ConvertToLetter = ConvertToLetter & Chr(iRemainder + 64)
   End If
End Function
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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