Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Unexpected issue with VBA code received

What the code does is moves the number data in excel from column C and
appends it to B.
It also formats that data to be in a "00000" data format because the
source data on my example from column C row 1 would look like 11.

The end result is it might look like this.

Widget 00011

My unexpected issue is that now I have some data that I believe excel
doesn't treat as a number. Some of the data

Example source

Column C row 2 = 11602-72401 Column B row 2 =Small Widget

end result = Small Widget11602-72401

as you can see the space between the txt and number don't exist. I
think because Excel treats the 11602-72401 number as text.


Here is the sample code:

Sub ConcatBandC()
Dim X As Long, LastRow As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For X = 2 To LastRow
Cells(X, "B").Value = Cells(X, "B").Value & Format( _
Cells(X, "C").Value, " 00000")
Next
End Sub

Any ideas on fixing the code so it will handle both examples?

Thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Unexpected issue with VBA code received

Well, 11602-72401 might be a number to you; but, since pure numbers do not
have symbols in the middle of them, then both excel and VB will see it as
text. However, if you move the space character outside of the Format
function's format pattern, I think your code will do what you want. Try it
this way and see if it works...

Cells(X, "B").Value = Cells(X, "B").Value & " " & Format( _
Cells(X, "C").Value, "00000")

--
Rick (MVP - Excel)


"srosetti" wrote in message
...
What the code does is moves the number data in excel from column C and
appends it to B.
It also formats that data to be in a "00000" data format because the
source data on my example from column C row 1 would look like 11.

The end result is it might look like this.

Widget 00011

My unexpected issue is that now I have some data that I believe excel
doesn't treat as a number. Some of the data

Example source

Column C row 2 = 11602-72401 Column B row 2 =Small Widget

end result = Small Widget11602-72401

as you can see the space between the txt and number don't exist. I
think because Excel treats the 11602-72401 number as text.


Here is the sample code:

Sub ConcatBandC()
Dim X As Long, LastRow As Long
LastRow = Cells(Rows.Count, "B").End(xlUp).Row
For X = 2 To LastRow
Cells(X, "B").Value = Cells(X, "B").Value & Format( _
Cells(X, "C").Value, " 00000")
Next
End Sub

Any ideas on fixing the code so it will handle both examples?

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 33
Default Unexpected issue with VBA code received

On Oct 28, 8:46*am, "Rick Rothstein"
wrote:
Well, 11602-72401 might be a number to you; but, since pure numbers do not
have symbols in the middle of them, then both excel and VB will see it as
text. However, if you move the space character outside of the Format
function's format pattern, I think your code will do what you want. Try it
this way and see if it works...

* * Cells(X, "B").Value = Cells(X, "B").Value & " " & Format( _
* * * * * * * * * * * * * Cells(X, "C").Value, "00000")

--
Rick (MVP - Excel)

"srosetti" wrote in message

...

What the code does is moves the number data in excel from column C and
appends it to B.
It also formats that data to be in a "00000" data format because the
source data on my example from column C row 1 would look like 11.


The end result is it might look like this.


Widget 00011


My unexpected issue is that now I have some data that I believe excel
doesn't treat as a number. *Some of the data


Example source


Column C row 2 = 11602-72401 * * Column B row 2 =Small Widget


end result = *Small Widget11602-72401


as you can see the space between the txt and number don't exist. *I
think because Excel treats the 11602-72401 number as text.


Here is the sample code:


Sub ConcatBandC()
*Dim X As Long, LastRow As Long
*LastRow = Cells(Rows.Count, "B").End(xlUp).Row
*For X = 2 To LastRow
* *Cells(X, "B").Value = Cells(X, "B").Value & Format( _
* * * * * * * * * * * * *Cells(X, "C").Value, " 00000")
*Next
End Sub


Any ideas on fixing the code so it will handle both examples?


Thanks




It works great. Thank You
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code issue fgwiii[_2_] Excel Programming 2 September 21st 09 07:56 PM
Code issue Tom Excel Programming 4 May 29th 07 10:31 AM
Pause code, wait for input, no input received, carry on with the code [email protected] Excel Programming 1 September 29th 05 12:19 PM
VBA Code issue scrabtree23[_3_] Excel Programming 2 December 4th 04 04:26 PM
unexpected problem in VBA Code Q[_2_] Excel Programming 1 December 4th 03 04:22 PM


All times are GMT +1. The time now is 06:01 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"