Excel计算2个字符串之间的行数

时间:2015-05-15 13:54:28

标签: excel vba

我需要在A列中放置行标题。这会因每个页面而异,所以我需要一个VBA来处理这个问题。我需要计算两个单元格之间的行数,然后对标题进行serielize。

enter image description here

enter image description here

所以我也需要

  1. Loop thrugh Column B
  2. sCell =查找
  3. 中的单元格
  4. Samples =计算s和Inspector之间的单元格
  5. StartCell = sCell + 1
  6. 将StartCell循环到样本
  7. 这是对的吗?

2 个答案:

答案 0 :(得分:0)

非VBA解决方案

(我个人认为VBA是不必要的)

您可以使用此公式从**OnCreate() :-** public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent returnIntent = new Intent(); setResult(RESULT_CANCELED, returnIntent); this.finish(); return true; } return super.onKeyDown(keyCode, event); } ActionBar mActionBar = getActionBar(); mActionBar.setDisplayShowHomeEnabled(false); mActionBar.setDisplayShowTitleEnabled(false); LayoutInflater mInflater = LayoutInflater.from(this); View mCustomView = mInflater.inflate(R.layout.actionbar_category_feed_list, null); RelativeLayout rrBack = (RelativeLayout) mCustomView.findViewById(R.id.rr_back); TextView title = (TextView) mCustomView.findViewById(R.id.txt_title); title.setText(""); title.setTypeface(typeFaceMedium); rrBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { mTracker.send(new HitBuilders.EventBuilder().setCategory("" + userUsername).setAction("On Search Feed Screen").setLabel("Pressed Back Button").build()); Intent returnIntent = new Intent(); setResult(RESULT_CANCELED, returnIntent); finish(); } }); mActionBar.setCustomView(mCustomView); mActionBar.setDisplayShowCustomEnabled(true); **actionbar_category_feed_list.xml** ?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="50dp" android:background="@android:color/white" > <RelativeLayout android:id="@+id/rr_back" android:layout_width="50dp" android:layout_height="50dp" android:layout_alignParentLeft="true" android:layout_centerVertical="true" > <ImageView android:id="@+id/img_logo" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:focusable="false" android:src="@drawable/back_red" /> </RelativeLayout> <com.converza.library.CustomTextView android:id="@+id/txt_title" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_centerVertical="true" android:layout_toRightOf="@+id/rr_back" android:gravity="center_vertical" android:paddingLeft="8dp" android:text="@string/app_name" /> </RelativeLayout> **At last in your fragment Activity use a OnactivityResult() for get a Returnintent from Activity.** @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == Const.FEEDDETAIL && resultCode == Activity.RESULT_OK) { Log.e(tag, "DatashBoard Const.FEEDDETAIL RESULT_OK"); } else if (requestCode == Const.FEEDDETAIL && resultCode == Activity.RESULT_CANCELED) { Log.e(tag, "DatashBoard Const.FEEDDETAIL RESULT_CANCELED"); } } 开始并自动填充:

A1

一些注意事项:

  1. 这适用于数字和文字
  2. 这不适用于空白
  3. 如果您要搜索的值唯一,则可能会出现意外结果
  4. 现在我硬编码&#34; S&#34;和&#34;检查员&#34;在这,但你可以将其改为单元格引用。让我们说=IFERROR(IF(AND(MATCH("S",B:B,0)<MATCH(B1,B:B,0),MATCH("Inspector",B:B,0)>MATCH(B1,B:B,0)),IFERROR(OFFSET(INDIRECT(CHAR(COLUMN()+64)&ROW()),-1,0)+1,1),""),"") D1(只记得使用绝对引用E1$D$1

    $E$1

答案 1 :(得分:0)

能够在没有循环的情况下执行此操作

Option Explicit

Sub MarkSamples()
    Dim FoundsCell As Range
    Dim FoundeCell As Range
    Dim cStart As String
    Dim cEnd As String
    Dim EndCell As String
    Dim sampCol As String
    Dim StartCell As String
    cStart = "s" & " " & "*"
    cEnd = " Inspector"

    Set FoundsCell = Sheets("Sheet1").Columns(2).Find(cStart, LookIn:=xlValues, LookAt:=xlWhole)

    Set FoundeCell = Sheets("Sheet1").Columns(2).Find(cEnd, LookIn:=xlValues, LookAt:=xlWhole)

    StartCell = FoundsCell.row + 1
    EndCell = FoundeCell.row - FoundsCell.row - 1

    sampCol = "A" & StartCell
    Range(sampCol) = 1
    Range(sampCol).Select
    Selection.DataSeries Rowcol:=xlColumns, Type:=xlLinear, Date:=xlDay, _
        Step:=1, Stop:=EndCell, Trend:=False


End Sub