Discrepancies between running macro and stepping through the code.

VBAwful

New Member
Joined
Sep 22, 2012
Messages
14
Hi guys,

I have just written a code to convert some numbers from text format (They were imported from a PDF) to number format. The code seems to work perfectly when I step through it and watch what it is doing, however when I assign the macro to a button it causes all the converted numbers to go to zero. My code is below.

Many thanks in advance for your help!


Code:
Sub Condition2()
For k = 8 To LastRow
Worksheets("Bordx Format").Cells(k, i - 1).Value = CDec(Cells(k, i - 1).Value)
Worksheets("Bordx Format").Cells(k, i - 1).NumberFormat = "0"
Next k
End Sub
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Which worksheet is Cells meant to refer to here?

Code:
CDec(Cells(k, i - 1).Value)
 
Upvote 0
Which worksheet is Cells meant to refer to here?

Code:
CDec(Cells(k, i - 1).Value)

Youl solved my problem. I included the worksheet object reference i.e.

Code:
CDec(Worksheets("Bordx Format").Cells(k,i-1).Value)

and it worked.

Great spot and thank you!!
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,732
Members
449,093
Latest member
Mnur

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