Code partially running then running

twoodsmall79

New Member
Joined
Jul 18, 2014
Messages
18
I have been searching all over with no luck so far. From Access I have the below code that updates a couple fields and fixes a number stored as text issue from a report downloaded daily that is ultimately part of a linked table. When I run this code the first time I get no errors but only the Cell names get updated. The second (or third) time I run this code the number stored as text issues are corrected. Any ideas why this is happening and how to prevent?

Code:
Sub AccrualBalance_Update()


Dim MySheetPath As String
Dim Xl As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet


MySheetPath = "H:\Agreement Balances.xlsx"


Set Xl = CreateObject("Excel.Application")
Set XlBook = GetObject(MySheetPath)


Set XlSheet = XlBook.Worksheets(1)


XlSheet.Range("A1") = "Sales Organization"
XlSheet.Range("B1") = "SoldToNum"
XlSheet.Range("C1") = "Agreement Type"
XlSheet.Range("D1") = "AgreementNum"
XlSheet.Range("L1") = "EndBal"
With XlSheet.UsedRange
    .Value = .Value
End With


XlSheet.Range("A:B", "D:D").NumberFormat = "0"
   
    
XlBook.Windows(1).Visible = True
XlBook.Save
XlBook.Close
Xl.Quit


End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try putting the .Value = .Value after the NumberFormat = "0", rather than before.
 
Upvote 0

Forum statistics

Threads
1,221,888
Messages
6,162,623
Members
451,778
Latest member
ragananthony7911

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