Adding a new column with VBA

W

wayward

Hello all, i currently have an excel worksheet that extracts data fro
one sheet (tabsdata) and displays in another worksheet
(trs) minus a few columns. The vba code I have to do this is a
follows:


Dim intRow As Integer, intRowTABS As Integer, intRowTRS As Integer

Sheets("TABS Data").Select

intRowTABS = Cells(Rows.Count, 2).End(xlUp).Row


For intRow = 2 To intRowTABS
If Left(Cells(intRow, 10), 6) = "BT2SAG" And Cells(intRow, 8)
"H" Then
With Sheets("TRS")
intRowTRS = .Cells(.Rows.Count, 2).End(xlUp).Row + 1

.Range(.Cells(intRowTRS, 1), .Cells(intRowTRS, 5)).Value
_
Range(Cells(intRow, 2), Cells(intRow, 6)).Value

.Range(.Cells(intRowTRS, 6), .Cells(intRowTRS, 8)).Value
_
Range(Cells(intRow, 8), Cells(intRow, 10)).Value

.Range(.Cells(intRowTRS, 9), .Cells(intRowTRS, 11)).Value
_
Range(Cells(intRow, 12), Cells(intRow, 14)).Value

End With
End If
Next intRow


<GUESSING I NEED SOMETHING HERE>



For intRow = 2 To intRowTABS
If Left(Cells(intRow, 10), 6) = "BT2SAG" And Cells(intRow, 8)
"H" Then
With Sheets("TRS")
intRowTRS = .Cells(.Rows.Count, 2).End(xlUp).Row + 1

.Range(.Cells(intRowTRS, 1), .Cells(intRowTRS, 5)).Value
_
Range(Cells(intRow, 2), Cells(intRow, 6)).Value

.Range(.Cells(intRowTRS, 6), .Cells(intRowTRS, 8)).Value
_
Range(Cells(intRow, 8), Cells(intRow, 10)).Value

.Range(.Cells(intRowTRS, 9), .Cells(intRowTRS, 11)).Value
_
Range(Cells(intRow, 12), Cells(intRow, 14)).Value

End With
End If
Next intRow



I have several criteria that I wish to search for and extract what
need to do is after its found a particular criteria and listed them
want to insert 3 rows and a row of titles as a spacer before nex
criteria is found.

The titles I wish to insert are:
Cost centre | Brief code | Brief Description | Project Code | Projec
Description | Charge type | Person Charge | Service Code | Hour | Rat
| Charge Amount




Thanks for your help
Kevi
 
D

Debra Dalgleish

Assuming you have your headings in row 1 on the TRS sheet, add this line
between the sections of code:

Worksheets("TRS").Rows(1).Copy _
Destination:=Worksheets("TRS").Rows(intRowTRS + 4)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top