Wrong number format

bobkap

Active Member
Joined
Nov 22, 2009
Messages
323
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I have a text field with entries like this: 001-2024. However, when I bring them over to another worksheet via VBA code I get the entry in scientific notation.
Any help would be greatly appreciated. I've tried reformatting the fields from and to but it still does not fix the problem.
 
Ok, so maybe post all the code ??
Only because it seems nothing suggested is solving the issue.
Thanks again! NOTE - I'm not using the counter yet until I confirm I have my first record correct.

VBA Code:
Sub DINSA_Mo_Report()
'
' DINSA_Mo_Report Macro
'
'Dim BK As Integer
'Dim wks As Worksheet
Dim toprow As Variant, finalrow As Variant, sdatecol As Variant, edatecol As Variant
toprow = 2
Sheets("Report").Activate
sdatecol = Worksheets("Report").Application.match("Start Date", Range("1:1"), 0)
edatecol = Worksheets("Report").Application.match("End Date", Range("1:1"), 0)
'finalrow = Worksheets("Main").Cells(Rows.Count, 1).End(xlUp).Row
sdate = Worksheets("Report").Cells(2, sdatecol)
EDate = Worksheets("Report").Cells(2, edatecol)
Dim Invordcol As Variant, Suppliercol As Variant, Invsdatecol As Variant, Invnumcol As Variant, Invamtcol As Variant, Invshipcol As Variant, typecol As Variant, repordcol As Variant
finalrow = Worksheets("Main").Cells(Rows.Count, 1).End(xlUp).Row

Sheets("Main").Activate


Suppliercol = Worksheets("Main").Application.match("Supplier", Range("1:1"), 0)
Invsdatecol = Worksheets("Main").Application.match("Invoice Date", Range("1:1"), 0)
Invnumcol = Worksheets("Main").Application.match("Invoice #", Range("1:1"), 0)
Invamtcol = Worksheets("Main").Application.match("Inv. Amt.", Range("1:1"), 0)
Invshipcol = Worksheets("Main").Application.match("Shipping", Range("1:1"), 0)
Sheets("Report").Activate
typecol = Worksheets("Report").Application.match("TYPE", Range("1:1"), 0)
repordcol = Worksheets("Report").Application.match("Order #", Range("1:1"), 0)
Invordcol = Worksheets("Report").Application.match("Order #", Range("1:1"), 0)


'For counter = Worksheets("Main").finalrow To 2 Step -1


    'Is invoice date in range of the report we're doing?
    If Worksheets("Main").Cells(finalrow, Invsdatecol) >= sdate And Worksheets("Main").Cells(finalrow, Invsdatecol) <= EDate Then
    'Worksheets("Report").Cells(toprow, Invordcol) = Worksheets("Main").Cells(finalrow, repordcol)
    Worksheets("Report").Cells(toprow, Invordcol) = "'" & Worksheets("Main").Cells(finalrow, repordcol).Text
    
    'next counter
    End If
'Next counter



'
End Sub
 
Upvote 0

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I have a text field with entries like this: 001-2024
So, in the source cell (in Worksheets("Main")), it shows 001-2024, right?
What does the formula bar show?
Could you post an image, showing both cell & formula bar?
 
Upvote 0
So, in the source cell (in Worksheets("Main")), it shows 001-2024, right?
What does the formula bar show?
Could you post an image, showing both cell & formula bar?
Actually, it's supposed to show 033-2024. By the way, please excuse my amateurish code writing. Here's that image.
 

Attachments

  • Screenshot 2024-05-02 193717.jpg
    Screenshot 2024-05-02 193717.jpg
    181.9 KB · Views: 3
Upvote 0
Base on your image, the value is in col F, so try:
VBA Code:
 Worksheets("Report").Cells(toprow, Invordcol) = "'" & Worksheets("Main").Cells(finalrow, "F").Text
 
Upvote 0
Solution
Also, maybe this before the pastingline
VBA Code:
Worksheets("Main").Cells(finalrow, repordcol)numberformat=  "@"
 
Upvote 0
Base on your image, the value is in col F, so try:
VBA Code:
 Worksheets("Report").Cells(toprow, Invordcol) = "'" & Worksheets("Main").Cells(finalrow, "F").Text
THAT WORKED!! MEGA THANKS!
 
Upvote 0
Also, maybe this before the pastingline
VBA Code:
Worksheets("Main").Cells(finalrow, repordcol)numberformat=  "@"
I seem to have found my solution but thanks very much!!
 
Upvote 0
Good to see you managed to get it sorted.....:cool:(y)
 
Upvote 0
You're welcome, glad to help & thanks for the feedback.:)
 
Upvote 0
bobkap,
Please note: When marking a post as the solution, please mark the original post that has the solution and not your own post indicating that another post is the solution.
I have updated this for you.
 
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,890
Members
449,477
Latest member
panjongshing

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