简体   繁体   中英

Excel VBA: Inserting Rows Based on Number contained in Cells

I think the easiest way to get the desired answer is to just describe the entire scenario. My company tracks projects using Primavera. The scheduler exports the data into Excel and manipulates the data for his own uses. He would like this manipulation to be automated using macros so that he doesn't have to repeat the same process every time. Most of it is fairly simple, but I have stumbled on this one part.

The first column in the workbook is the project number + name. There are two types of projects: small projects that have a 3 digit number with an optional subtask number and large projects that have a 4 digit number with an optional subtask number. The cell is comprised of both numbers and text. The general format is as follows:

Small Projects

123 Small Project #1

or

123-4 Small project #2

Large Projects

1234 Large Project #1

or

1234-5 Large Project #2

He inserts three rows to separate the two project types (small projects and large projects are always lumped together). Is there a way, using VBA, to automate this process?

I was thinking it would go along the lines of "if first four characters in cell are numbers, then LargeProject = LargeProject + 1, else SmallProject = SmallProject + 1". Just don't know what expression (if one exists) can be utilized to accomplish this.

Thanks!

If txt Like "### *" or txt Like "###-*" Then
   'small project
Elseif txt Like "#### *" or txt like "####-*" Then
   'large project
End If

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM