2014-02-19 23 views
-1

我有一个客户列表的编辑,我想将其格式化为Excel表格格式。如上图所示,是否有办法从客户列表中提取数据并将其插入表中? 我无法手动完成,因为客户太多。Excel:重新定位excel中的数据

有没有可以做到的附加功能或公式?

enter image description here

+1

你有没有尝试过自己呢?一般来说,如果你尝试自己并发布你的代码,如果你正在挣扎,你会得到更好的回应。简而言之,使用VBA有一个相当简单的方法,你之前使用过VBA吗? – Simon1979

+0

嗨西蒙。很遗憾,我不熟悉VBA。你有一个示例代码,我可以试错吗? – nelsonq

+0

此网站旨在帮助人们解决他们的编程问题,而不是提供完整的解决方案。如果你不准备至少为自己编写一些代码,那么你就错了。 –

回答

0

既然你是完全新的VBA我给你一条腿,这一次,但通常你需要出示你有什么先做自己获得任何援助。

快速介绍VBA;按Alt + F11调出VBE(Visual Basic编辑器),进入插入并点击模块。粘贴下面的代码,然后修改它,添加剩余的数据点并计算出行/列偏移量。您可以按F5运行代码。

Sub RePosition() 

Dim rng As Range, c As Range, dest As Range 

' Set the range to look in for "CustomerNo:" 
Set rng = ActiveSheet.Range("A:A") 
' Set the cell where you want to start putting you re-positioned data 
Set dest = Range("I2") 

' Loop through each cell in you range 
For Each c In rng 
    ' If the cell = "CustomerNo:" we know it is a new set 
    ' of data 
    If c.Value = "CustomerNo:" Then 
     ' Based from the cell containing "CustomerNo:" we can 
     ' pick up each data point by offsetting row and column 
     ' and place it in our destination cell (offsetting dest 
     ' as well) 
     c.Offset(0, 1).Copy dest 
     c.Offset(1, 1).Copy dest.Offset(0, 1) 
     c.Offset(2, 1).Copy dest.Offset(0, 2) 
     c.Offset(2, 3).Copy dest.Offset(0, 3) 
     ' etc for each of the data points 


     ' Set the dest to the row below 
     Set dest = dest.Offset(1, 0) 
    End If 
Next c 

End Sub 

这应该让你开始,给你如何对待它,如果你运行它是你应该得到的客户,公司,名称和地址渡过难关,你应该能够推测的一个想法自己休息一下。

+0

非常感谢!管理使用您的代码并将其编辑为我的要求。它工作完美! – nelsonq