TA的每日心情 | 怒 2018-9-20 16:30 |
---|
签到天数: 43 天 [LV.5]常住居民I
|
马上注册,下载丰富资料,享用更多功能,让你轻松玩转阳光石油论坛。
您需要 登录 才可以下载或查看,没有账号?欢迎注册
x
本帖最后由 pyangguang1004 于 2014-11-23 17:24 编辑
最近需要在Jason中加载上百口井的井斜数据,而甲方给的井斜数据是放在数据表中的。本人不才,一时不知道怎么加载了……
想起之前学的一点点VBA知识,耗费了周末一天的时间写了下面这段代码,成功的解决了数据加载的问题。特与各位共享:
Sub Macro1()
Dim st, ed, fn, i, r
With Sheets("Sheet1")
r = .Range("a65536").End(xlUp).Row
i = 2
Do While i < r
st = i
Do While Cells(i, 1) = Cells(i + 1, 1)
i = i + 1
Loop
ed = i
With Sheets("Sheet1")
fn = Cells(st, 1)
.Range(Cells(st, 2), Cells(ed, 5)).Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
ActiveCell.FormulaR1C1 = "MD"
Range("B1").Select
ActiveCell.FormulaR1C1 = "TVD"
Range("C1").Select
ActiveCell.FormulaR1C1 = "DX"
Range("D1").Select
ActiveCell.FormulaR1C1 = "DY"
ActiveWorkbook.SaveAs ThisWorkbook.Path & "\" & fn & ".txt", _
FileFormat:=xlText, CreateBackup:=False
ActiveWorkbook.Close
End With
i = i + 1
Loop
End With
End Sub
|
评分
-
查看全部评分
|