使用Vb代码将单元格拆分为多行 [英] Split Cells Into Multiple Rows using Vb Code

查看:119
本文介绍了使用Vb代码将单元格拆分为多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因为我是Vb excel的新手.有人可以建议我如何使用Vb代码将单元拆分为多行.我尝试了一些代码,但是没有用.

As I am new to Vb excel. Can someone suggest me how I can Split Cells Into Multiple Rows using Vb Code. I have tried few code but not working.

示例数据:

推荐答案

以下是帮助您入门的示例.

Here is an example to get you started.

此代码将获取您突出显示的活动单元格,并用空格将字符串分解,将其扩展到第1行的各列.

This code will take the active cell you have highlighted and break up the string by spaces, expanding it across columns in row 1.

示例:

  1. 单元格A5包含"Hello World测试"
  2. 突出显示单元格A5
  3. 给子打电话
  4. 代码将执行,您现在在A1中具有"Hello",在A2中具有"World",在A3中具有"Test"

  1. Cell A5 contains "Hello World Test"
  2. Highlight cell A5
  3. Call the sub
  4. The code will execute and you will now have "Hello" in A1, "World" in A2, and "Test" in A3

Sub Example()
    Dim txt As String
    Dim i As Integer
    Dim fullname As Variant

    txt = ActiveCell.Value
    fullname = Split(txt, " ")
    For i = 0 To UBound(fullname)
        Cells(1, i + 1).Value = fullname(i)
        MsgBox fullname(i)
    Next i
End Sub

这篇关于使用Vb代码将单元格拆分为多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆