Need help to modify the code so the comma wont appear after the value...

mars91

New Member
Joined
Jul 8, 2011
Messages
48
Need help to modify the code so the comma wont appear after the value... Here is one part of code :

Code:
sht2.Cells(b, 2).Value = sht2.Cells(b, 2).Value + 1
[COLOR=red]sht2.Cells(b, 3).Value = sht1.Cells(a, 3) + "," + sht2.Cells(b, 3).Value[/COLOR]
[COLOR=red]sht2.Cells(b, 4).Value = sht1.Cells(a, 10) + "," + sht2.Cells(b, 4).Value[/COLOR]

I will have search for date from sht1 then look for one particular item name if it have appear on that date. After that input the number of counts in sht2.

Cells beside the number counts are those cells with "item colours names" which are also get from sht1.
This code work but here is the problem..

After the macro run, it calculate the right n but for the item colour indicate beside the count cells have a extra "comma".

Example like this..for 2 counts, the item colours names.
Red,Blue, <<<< This comma in red is the extra comma which i do not want.

"The code highlighted in red are the source of the problem", but i do not know how to fix it so i can get rid that extra comma..

I have help to modify,pls give me guide me..

Thank in advance
 
Last edited:

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This will remove the last character (comma) from sht2.Cells(b, 4)
Code:
With sht2.Cells(b, 4)
    .Value = Left(.Value, Len(.Value) - 1)
End With
 
Upvote 0
Hi AlphaFrog,

Thank you, i tried ur code, it works.


I have another problem..

After the macro run for 1 time, if i run the macro agn without empty those values.

Then it will duplicate one more time. Like this : "Red,Blue,Red,Blue".

What can i do to solve this? Can You help or Anyone help?
If you need my whole code,i can display it here.

Thank in Advance
 
Upvote 0
Somewhere in your code before you loop to fill values in the cells, you should clear the destination cells.
Code:
sht2.Cells(b, 4).ClearContents
 
Upvote 0

Forum statistics

Threads
1,224,507
Messages
6,179,183
Members
452,893
Latest member
denay

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