excel宏命令修改的疑问,判断字符串
如图1,我的原文件格式如图一,所圈单元格的下方格式为(XXXX*XXX)即为*字符加数字,其下下方单元格格式为(MO:XXX)即为MO:加数字,我有宏代码,可以实现图二所...
如图1,我的原文件格式如图一,所圈单元格的下方格式为(XXXX*XXX)即为*字符加数字,其下下方单元格格式为(MO:XXX)即为MO:加数字,我有宏代码,可以实现图二所示的快捷复制到粘贴其右下方单元格,现在我想实现图三的快捷复制粘贴,即是只复制*字前的内容,还有指复制*字后的内容,和只复制MO:后的内容,实现结果为图三所示,请高手修改下,谢谢!因不知怎么传附件,故传不了文档,宏代码在最下边,谢谢!
图一
图二
图三
Sub 宏1()
Selection.Copy
ActiveCell.Offset(3, 3).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(-2, -3).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(2, 2).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(-1, -2).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(0, 0).Range("A1").Select
Application.CutCopyMode = False
End Sub 展开
图一
图二
图三
Sub 宏1()
Selection.Copy
ActiveCell.Offset(3, 3).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(-2, -3).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(2, 2).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(-1, -2).Range("A1").Select
Application.CutCopyMode = False
Selection.Copy
ActiveCell.Offset(1, 1).Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveCell.Offset(0, 0).Range("A1").Select
Application.CutCopyMode = False
End Sub 展开
2个回答
展开全部
把原来的宏改为这个试试:
Sub 宏1()
Dim str(5) As String
myrow = Selection.Row
mycol = Selection.Column
str(3) = Selection.Text
tmp = Cells(myrow + 2, mycol).Value
str(1) = Right(tmp, Len(tmp) - 3)
tmp = Cells(myrow + 1, mycol).Value
str(2) = Left(tmp, InStr(tmp, "*") - 1)
str(4) = Right(tmp, Len(tmp) - InStr(tmp, "*"))
str(5) = str(4)
For i = 1 To 5
Cells(myrow + 3, mycol + i).Value = str(i)
Next
End Sub
需要注意的是运行前需要先选中C4单元格(其内容为B1)
展开全部
直接用赋值
sub 宏1()
i=activecell.row
j=activecell.column
cells(i+3,j+1) =right(cells(i+2,j),len(cells(i+2,j))-3)
cells(i+3,j+2) =left(cells(i+1,j),instr(1,cells(i+1,j),"*")-1)
cells(i+3,j+3) =cells(i,j)
cells(i+3,j+4) =mid(cells(i+1,j),instr(1,cells(i+1,j),"*")+1,len(cells(i+1,j)))
cells(i+3,j+5) = cells(i+3,j+4)
end sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询