楼主: regus
1921 2

解决我vba问题的重赏 [推广有奖]

  • 1关注
  • 13粉丝

已卖:1958份资源

讲师

14%

还不是VIP/贵宾

-

威望
0
论坛币
19751 个
通用积分
8.9336
学术水平
14 点
热心指数
13 点
信用等级
10 点
经验
21899 点
帖子
227
精华
0
在线时间
481 小时
注册时间
2006-5-15
最后登录
2024-8-2

楼主
regus 发表于 2010-2-18 03:30:21 |AI写论文
200论坛币
我有个工作簿workbook,里面有很多工作表worksheets。每个工作表格式都一样。但是由于内容长短不一,造成不用的工作表核心内容开始的地方不一样。我为了能应用函数摘出核心内容,想把它们的格式都统一起来。所以我的目的是,查找每个worksheet第一列(也就是A列)里的内容“profile”(只有一个)。如果profile所在行的行数小于31,那在其上方插入一行,直到profile处在第31行,这样profile以后的内容都是规则的了。
请给出vba代码。谢谢。我vba在初学阶段,格式不太熟悉,所以不知道自己用对没有。请高手指教。

关键词:VBA worksheets worksheet workbook Profile VBA 解决 重赏

回帖推荐

wise 发表于3楼  查看完整内容

帮2楼简化了一下代码。

empxiang 发表于2楼  查看完整内容

Dim i As Integer Dim j As Integer Dim intRow As Integer For i = 1 To ThisWorkbook.Sheets.Count ThisWorkbook.Sheets(i).Activate Columns("A:A").Select Selection.Find(What:="profile", After:=ActiveCell, LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate intRo ...

本帖被以下文库推荐

沙发
empxiang 发表于 2010-2-18 11:13:10
Dim i As Integer
Dim j As Integer
Dim intRow As Integer
For i = 1 To ThisWorkbook.Sheets.Count
    ThisWorkbook.Sheets(i).Activate
    Columns("A:A").Select
    Selection.Find(What:="profile", After:=ActiveCell, LookIn:=xlFormulas, _
        LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, MatchByte:=False, SearchFormat:=False).Activate
    intRow = ActiveCell.Row
    If intRow < 31 Then
        Rows(intRow & ":" & intRow).Select
        For j = intRow To 30
            Selection.Insert Shift:=xlDown
        Next j
        
    End If
   
Next i
把上面的代码放到Workbook_Open()中
已有 1 人评分论坛币 热心指数 收起 理由
客初 + 20 + 2 热心帮助其他会员

总评分: 论坛币 + 20  热心指数 + 2   查看全部评分

藤椅
wise 发表于 2010-2-19 23:24:02
帮2楼简化了一下代码。
  1. Sub a()
  2. Dim i As Integer
  3. Dim j As Integer
  4. Dim intRow As Integer
  5. For i = 1 To ThisWorkbook.Sheets.Count
  6.     ThisWorkbook.Sheets(i).Activate
  7.     Columns("A:A").Select
  8.     Selection.Find(What:="profile").Activate
  9.     intRow = ActiveCell.Row
  10.     If intRow < 31 Then
  11.         Rows(intRow & ":" & intRow).Select
  12.         For j = intRow To 30
  13.             Selection.Insert Shift:=xlDown
  14.         Next j
  15.     End If
  16. Next i
  17. End Sub
复制代码
已有 1 人评分论坛币 热心指数 收起 理由
客初 + 20 + 2 热心帮助其他会员

总评分: 论坛币 + 20  热心指数 + 2   查看全部评分

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-28 16:25