Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split cell string into individual cells

I am unable to split a single cell's value into two different strings and put both of those strings in different cells.

For instance I want to take a measurement 10ft x 20ft value in a cell and take the 10ft and put it in another cell, and take the 20ft and put it in a completely different cell.

I'd like to use a delimiter x or something, but I just don't know how to take those separations and do something with them after the split.

Any tips would be much appreciated. I'm still pretty new to VBA macros.

Thanks

like image 549
cheapkid1 Avatar asked Dec 21 '22 14:12

cheapkid1


2 Answers

The best solution is using SPLIT

Dim strX As String
Dim sx() As String
Dim i as Integer
strX = "10FT x 20FT"
sx = Split(strX, "x")

Or maybe you can use instr function

Dim sVar1 as string
Dim sVar2 as string

I = InStr(1, strX, "x")

Now you know where can split int two variables

sVar1 = mid(strX, 1, I)
sVar2 = mid(strx,i+1)

The problem with the function is that if you have several keys in the chain with which you want to separate your function will return an array larger. For example: Dim var as string var = "x 20XP 10XP"

returns

array (0) = "10"
array (1) = "p"
array (2) = "20"
array (3) = "p"
like image 73
manuerumx Avatar answered Jan 03 '23 06:01

manuerumx


You don't actually need VBA. You can use Excel's Text to Columns

For example, in excel-2010

  1. Data ..... Text to Columns
  2. Pick delimited and press Next
  3. Check Space and put 'x' in Other and press Next
  4. Finish

enter image description here

like image 35
brettdj Avatar answered Jan 03 '23 06:01

brettdj