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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
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,216,086
Messages
6,128,736
Members
449,466
Latest member
Peter Juhnke

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