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! :laugh:


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

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
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,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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