Loop function!

Lbarron

New Member
Joined
Nov 3, 2017
Messages
7
Hi all,

I'm trying to write some code in excel vba that will use the loop command to print numbers to cells, say from 1 to 100. I can get the numbers to print to cells however what I also need is each number to be wrapped in symbols like this.

"X" ,

Including the comma.

I've tried a few things but loose the effect due to the compiler seeing the comma as a next expression.

My last code was basically ......value = i ± 1
Next i

Any idea please?
 
Hi,

Thanks the below worked however i changed the second ans and added another string called anc. This allowed the last " to include a semi colon. anc = """:".

I changed this because i cant type a comma without excel thinking its the end of an expression.

Class this one as solved. HOWEVER!!! - would you know how to make the print out move to the next line after every three numbers stroke cells being filled so it would look like the below?

Thanks alot for your help, i'm being greedy with the above, its just less manual data handling! :LOL:


Is this what you want:
Code:
Sub Count_Me()
Dim i As Long
Dim ans As String
ans = """"
    For i = 1 To 20
        Cells(i, 1).Value = ans & i & ans
    Next
End Sub
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
I changed this because i cant type a comma without excel thinking its the end of an expression.
What exactly did you mean by the above. Can you post the code you tried to use that did not work for you?

By the way, just out of curiosity, you did not respond to what I posted in Message #10 ... does that mean you have seen code like what I posted before?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,066
Messages
6,128,571
Members
449,458
Latest member
gillmit

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