如何自定义从网络获取的动态数据到excel
从Web获取的示例数据粘贴到excel / word中时显示如下:
1
Application has not up for the below reasons:
a. Low Processor Speed
b. Power failure
c. Under Maintenance
All Application issues resolved on 10/04
2
System has to process instructions defined
System has processed these instructions:
Executing commands
Sending auto email
Logging Response status in LogViewer
3
Send email
Email sent to the below group:
BackEnd Team
Network users
Group MGRS
4
Start the application
Application started successfully
预期的表格格式为:
Sl.No Description Comments
1 Application has not up for the below reasons: All Application issues resolved on 10/04
a. Low Processor Speed
b. Power failure
c. Under Maintenance
2 System has to process instructions defined System has processed these instructions:
Executing commands
Sending auto email
Logging Response status in LogViewer
3 Send email Email sent to the below group:
BackEnd Team
Network users
Group MGRS
4 Start the application Application started successfully
我尝试将Text设置为列或定界等,但未获得预期的输出。
答案 0 :(得分:0)
您可以使用此公式,将输出的每一列的最后一个参数从+1
更改为+3
。
=INDEX(A:A,(ROW()-1)*3+1)
图片显示了第三列所使用的公式
请注意,如果您的输入或输出数据不在第1行开始,那么您需要进行如下更改:
即将公式=INDEX($A:$A,(ROW(A1)-1)*3+ROW($A$6)+COLUMN(A3)-1)
放在要开始输出的单元格中。将$A:$A
更改为包含输入数据的列,并将$A$6
更改为输入数据开始的单元格。
答案 1 :(得分:0)
代码假定您的数据中没有空白单元格,我将初始数据放在A列中。
代码的第一部分是根据您的需要修改代码。
您设置工作表名称:ActiveWorkbook.Worksheets("Sheet1")
您决定从哪一行开始(包括标题):startrow = 1
还有要移动到的新列中的名称:SheetName.Cells(1, 2) = "Sl.No"
等。
请注意,代码创建了一个全新的表(复制和粘贴),带有数据的旧列将在末尾删除。
VBA代码
Sub MoveCells()
Dim lrow As Integer
Dim lrowno As Integer
Dim lrowname As Integer
Dim lrowcity As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim startrow As Integer
Dim SheetName As Worksheet
'################## Set variables ##################
Set SheetName = ActiveWorkbook.Worksheets("Sheet1") 'Name your worksheet
startrow = 1 'Set row number you want to sart the loop from
'Name first header rows
SheetName.Cells(1, 2) = "Sl.No" 'Column B = 2
SheetName.Cells(1, 3) = "Name" 'Column C = 3
SheetName.Cells(1, 4) = "City" 'Column D = 4
'################## Execute Code ##################
lrow = Cells(Rows.Count, 1).End(xlUp).Row 'Check the last row in Column A.
For i = startrow + 1 To lrow Step 3 'start from row 1 and add 1 row. Then loop to row lrow. After every loop it jump 3 rows.
lrowno = Cells(Rows.Count, 2).End(xlUp).Row 'Find last row in column B
SheetName.Cells(lrowno + 1, 2) = SheetName.Cells(i, 1) 'Copy Cells from Column A to Column B's last row
Next i
For j = startrow + 2 To lrow Step 3 'start from row 1 and add 2 rows. Then loop to row lrow. After every loop it jump 3 rows.
lrowname = Cells(Rows.Count, 3).End(xlUp).Row 'Find last row in Column C
SheetName.Cells(lrowname + 1, 3) = SheetName.Cells(j, 1) 'Copy Cells from Column A to Column C's last row
Next j
For k = startrow + 3 To lrow Step 3 'start from row 1 and add 3 rows. Then loop to row lrow. After every loop it jump 3 rows.
lrowcity = Cells(Rows.Count, 4).End(xlUp).Row 'Find last row in Column D
SheetName.Cells(lrowcity + 1, 4) = SheetName.Cells(k, 1) 'Copy Cells from Column A to Column D's last row
Next k
'Delete first column
Columns(1).EntireColumn.Delete
End Sub
答案 2 :(得分:-2)
尝试使用保留源格式来保持所复制内容的格式。
快捷方式为-> CTRL + K
链接到有关粘贴以保留格式的文章-> https://support.office.com/en-us/article/copy-cell-data-and-paste-attributes-only-0636593a-985c-4c34-bcfa-049f470a6596