ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   splitting a cell into 2 (https://www.excelbanter.com/excel-programming/297147-splitting-cell-into-2-a.html)

alldreans

splitting a cell into 2
 
Hello,

I can't figure this one out. Via a web query, I get a
value for H2 of "1,926.09 - 1,954.62".

I'd like to, through VBA, split the value in H2 and
paste them into 2 cells, I2 and J2. The f'inal result
would be I2 = "1,926.09" and J2 = "1,954.62".

Can anyone help me?

Thanks in advance

Frank Kabel

splitting a cell into 2
 
Hi
why not use a non-VBA solution: Use 'Data - Text to
columns'

Or is VBA required for you?

-----Original Message-----
Hello,

I can't figure this one out. Via a web query, I get a
value for H2 of "1,926.09 - 1,954.62".

I'd like to, through VBA, split the value in H2 and
paste them into 2 cells, I2 and J2. The f'inal result
would be I2 = "1,926.09" and J2 = "1,954.62".

Can anyone help me?

Thanks in advance
.


alldreams

splitting a cell into 2
 
Hi Frank,

VBA would be ideal so I can have one macro do it all in
one click.

-----Original Message-----
Hi
why not use a non-VBA solution: Use 'Data - Text to
columns'

Or is VBA required for you?

-----Original Message-----
Hello,

I can't figure this one out. Via a web query, I get a
value for H2 of "1,926.09 - 1,954.62".

I'd like to, through VBA, split the value in H2 and
paste them into 2 cells, I2 and J2. The f'inal result
would be I2 = "1,926.09" and J2 = "1,954.62".

Can anyone help me?

Thanks in advance
.

.


Frank Kabel

splitting a cell into 2
 
Hi
try (watch for linewraps):

Sub split_rows()
Dim RowNdx As Long
Dim LastRow As Long
Dim left_val
Dim right_val

Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "H").End(xlUp).Row
For RowNdx = LastRow To 1 Step -1
With Cells(RowNdx, "H")
If .Value < "" Then
left_val = CDbl(Trim(Left(.Value, InStr
(.Value, "-") - 1)))
right_val = CDbl(Trim(Mid(.Value, InStr
(.Value, "-") + 1, 15)))
.Offset(0, 1).Value = left_val
.Offset(0, 2).Value = right_val
End If
End With
Next RowNdx
Application.ScreenUpdating = True
End Sub


-----Original Message-----
Hi Frank,

VBA would be ideal so I can have one macro do it all in
one click.

-----Original Message-----
Hi
why not use a non-VBA solution: Use 'Data - Text to
columns'

Or is VBA required for you?

-----Original Message-----
Hello,

I can't figure this one out. Via a web query, I get a
value for H2 of "1,926.09 - 1,954.62".

I'd like to, through VBA, split the value in H2 and
paste them into 2 cells, I2 and J2. The f'inal result
would be I2 = "1,926.09" and J2 = "1,954.62".

Can anyone help me?

Thanks in advance
.

.

.


alldreams

splitting a cell into 2
 
Hi Frank,

thanks a bunch!


-----Original Message-----
Hi
try (watch for linewraps):

Sub split_rows()
Dim RowNdx As Long
Dim LastRow As Long
Dim left_val
Dim right_val

Application.ScreenUpdating = False
LastRow = ActiveSheet.Cells(Rows.Count, "H").End

(xlUp).Row
For RowNdx = LastRow To 1 Step -1
With Cells(RowNdx, "H")
If .Value < "" Then
left_val = CDbl(Trim(Left(.Value, InStr
(.Value, "-") - 1)))
right_val = CDbl(Trim(Mid(.Value, InStr
(.Value, "-") + 1, 15)))
.Offset(0, 1).Value = left_val
.Offset(0, 2).Value = right_val
End If
End With
Next RowNdx
Application.ScreenUpdating = True
End Sub


-----Original Message-----
Hi Frank,

VBA would be ideal so I can have one macro do it all in
one click.

-----Original Message-----
Hi
why not use a non-VBA solution: Use 'Data - Text to
columns'

Or is VBA required for you?

-----Original Message-----
Hello,

I can't figure this one out. Via a web query, I get

a
value for H2 of "1,926.09 - 1,954.62".

I'd like to, through VBA, split the value in H2 and
paste them into 2 cells, I2 and J2. The f'inal

result
would be I2 = "1,926.09" and J2 = "1,954.62".

Can anyone help me?

Thanks in advance
.

.

.

.



All times are GMT +1. The time now is 10:08 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com