How to pass a Textbox value of any word/sentence (e.g. "Apple" or "Apple is a fruit.") and split it into different cells in a row?

sunilhaokha

New Member
Joined
Aug 10, 2020
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Hi everyone, I have been trying to solve this Excel VBA code. Please help me!

Question: How to pass a Textbox value of any word/sentence (e.g. "Apple" or "Apple is a fruit.") and split it into different cells in a row with single letter each in the cell from the value including the spaces or period (say result for the word "Apple" should be - A1 ="A", A2 ="p", A3="p", A4="l" A5="e" or for the sentence "Apple is a fruit." should be - A1 ="A", A2 ="p", A3="p", A4="l" A5="e", A6=" ", A7="i", A8="s", A9=" ", A10="a", A11=" ", A12="f", A13="r", A14="u", A15="i", A16="t", A17=".")? Here I am taking just the examples. The TextBox Value can be anything and cell in a sheet can be in any row.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,544
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Give this code a try in whatever procedure you are using (change the YourTextBoxName stand-in text below to the actual name of your TextBox)...
Rich (BB code):
  Dim Arr As Variant
  Arr = Split(StrConv(YourTextBoxName.Text, vbUnicode), Chr(0))
  Range("B1").Resize(, UBound(Arr) + 1) = Arr
 
Solution

sunilhaokha

New Member
Joined
Aug 10, 2020
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
Give this code a try in whatever procedure you are using (change the YourTextBoxName stand-in text below to the actual name of your TextBox)...
Rich (BB code):
  Dim Arr As Variant
  Arr = Split(StrConv(YourTextBoxName.Text, vbUnicode), Chr(0))
  Range("B1").Resize(, UBound(Arr) + 1) = Arr
Thank you Rick Rothstein. These lines works well.
 

Forum statistics

Threads
1,147,481
Messages
5,741,400
Members
423,657
Latest member
Medrok2021

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
Top