Using Countif when searching for partial strings in cells - vba

Looking for some help using both COUNTIF and INSTR to determine the number of separate occurrences of a string in a set of data. I have the COUNTIF statements working for the cell values, but I am now trying to dig into the cells, and identify how many instances of a particular string occur across the entire column.
The code I have is as follows:
j = 2
Cells(2, 11) = "Active, non-corresp add"
Cells(3, 11) = "No start date of res"
Cells(4, 11) = "Invalid address"
Cells(5, 11) = "Active ID, no country"
Cells(6, 11) = "Invalid address format"
Cells(7, 11) = "Invalid characters in address"
While Cells(j, 11) <> vbNullString
s = WorksheetFunction.CountIf(Worksheets("Addresses Master").Range("N:N"), Cells(j, 11))
If s <> 0 Then
Cells(j, 12) = s
End If
t = WorksheetFunction.CountIfs(Worksheets("Addresses Master").Range("N:N"), Cells(j, 11), Worksheets("Addresses Master").Range("I:I"), 1)
If t <> 0 Then
Cells(j, 13) = t
End If
u = WorksheetFunction.CountIfs(Worksheets("Addresses Master").Range("N:N"), Cells(j, 11), Worksheets("Addresses Master").Range("I:I"), 0)
If u <> 0 Then
Cells(j, 14) = u
End If
k = 15
If Cells(j, 11) = "Review address" Then
p = 0
Else
p = 1
End If
While k <= 19
v = WorksheetFunction.CountIfs(Worksheets("Addresses Master").Range("N:N"), Cells(j, 1), Worksheets("Addresses Master").Range("I:I"), p, Worksheets("Addresses Master").Range("C:C"), Cells(1, k))
If v <> 0 Then
Cells(j, k) = v
v = 0
End If
k = k + 1
Wend
j = j + 1
s = 0
t = 0
u = 0
Wend
In the cells being searched, there could be a combination of the 6 strings that I am looking for (Cells 2 - 7).
Edit: clarified title

Resolved the issue through the use of wildcards.
Instead of trying to use something like InStr, the use of an asterisk before and after the cell location being searched for allows for the Countif function to search inside the cell.
i.e. "*" & cells(j,11) & "*"
The code then becomes:
j = 2
Cells(2, 11) = "Active, non-corresp add"
Cells(3, 11) = "No start date of res"
Cells(4, 11) = "Invalid address"
Cells(5, 11) = "Active ID, no country"
Cells(6, 11) = "Invalid address format"
Cells(7, 11) = "Invalid characters in address"
While Cells(j, 11) <> vbNullString
s = WorksheetFunction.CountIf(Worksheets("Addresses Master").Range("N:N"), "*" & Cells(j, 11) & "*")
If s <> 0 Then
Cells(j, 12) = s
End If
k = 13
p = 1
While k <= 19
v = WorksheetFunction.CountIfs(Worksheets("Addresses Master").Range("N:N"), "*" & Cells(j, 11) & "*", Worksheets("Addresses Master").Range("I:I"), p, Worksheets("Addresses Master").Range("C:C"), Cells(1, k))
If v <> 0 Then
Cells(j, k) = v
v = 0
End If
k = k + 1
Wend
j = j + 1
s = 0
t = 0
u = 0
Wend

Related

Unable to get the interior property of the range class - Run time error 1004

The code below is taken from the link Similar values in range make it as a KEY and sum function, however, I have made small adjustments to it (adding more cells to be checked). What the code does, is to check if columns 4, 5, 8, 36 and 37 have similar values/text in their cells. If yes, then it looks in column 59 and uses the sum function to check if the values of the similar entries are less or higher than 100. If yes, then the cells in column 59 turn red, if not, they should remain white.
Example:
Column 4: Cell D5, D6 and D7 - all are P11
Column 5: Cell E5, E6 and E7 - all are P12
Column 8: Cell H5, H6 and H7 - all are P13
Column 36: Cell AJ5, AJ6 and AJ7 - all are P14
Column 37: Cell AK5, AK6 and AK7 - all are P15
Column 59: Cell BG5 = 40 and BG6 = 20 and BG7 = 30. Total value: 90 which does not equal 100. Henceforth, BG5, BG6 and BG7 must turn red. (the sum function works only when the other columns mentioned have similar value in their rows)
The code worked when it was checking only the columns 4, 5 and 8 and no error was received. However, after I added also the columns 36 and 37, the following error is received: Unable to get the interior property of the range class - Run time error 1004 and I don't know how to solve this.
Note: The columns 4, 5, 8, 36, 37 and 59 also have the conditional formatting formula isblank to turn the cells red if they are empty. The reason for that is because people need to know that those cells are mandatory to complete.
Thanks for your help and time!
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, sum1 As Long, k As Long, c(5000) As Long
Application.EnableEvents = False
Range("bg5:bg5000").Interior.Color = RGB(255, 255, 255)
For i = 5 To 4999
k = 0
For j = i + 1 To 5000
If Cells.Interior.Color <> RGB(255, 0, 0) Then
If Cells(i, 4) & Cells(i, 5) & Cells(i, 8) & Cells(i, 36) & Cells(i, 37) <> "" Then
If Cells(i, 4) = Cells(j, 4) And Cells(i, 5) = Cells(j, 5) And Cells(i, 8) = Cells(j, 8) And Cells(i, 36) = Cells(j, 36) And Cells(i, 37) = Cells(j, 37) Then
If k = 0 Then sum1 = Cells(i, 59): k = 1: c(k) = i
sum1 = sum1 + Cells(j, 59)
k = k + 1
c(k) = j
End If
End If
End If
Next j
If sum1 <> 100 Then
For j = 1 To k
Cells(c(j), 59).Interior.Color = RGB(255, 0, 0)
Next j
End If
Next i
Application.EnableEvents = True
End Sub
here a proposal to adapt the code. Note that the macro runs each time you enter a value in column 59 and that it executes the code insides the loop for about 2500000 times, this may take some time.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Long, j As Long, sum1 As Long, k As Long, c(5000) As Long
If Target.Column <> 59 Then Exit Sub
Application.EnableEvents = False
Range("bg5:bg5000").Interior.Color = RGB(255, 255, 255)
For i = 5 To 4999
k = 0
If Cells(i, 4) & Cells(i, 5) & Cells(i, 8) & Cells(i, 36) & Cells(i, 37) <> "" Then
If Cells(i, 59).Interior.Color <> RGB(255, 0, 0) Then
For j = i + 1 To 5000
If Cells(j, 59).Interior.Color <> RGB(255, 0, 0) Then
If Cells(j, 4) & Cells(j, 5) & Cells(j, 8) & Cells(j, 36) & Cells(j, 37) <> "" Then
If Cells(i, 4) = Cells(j, 4) And Cells(i, 5) = Cells(j, 5) And Cells(i, 8) = Cells(j, 8) And Cells(i, 36) = Cells(j, 36) And Cells(i, 37) = Cells(j, 37) Then
If k = 0 Then sum1 = Cells(i, 59): k = 1: c(k) = i
sum1 = sum1 + Cells(j, 59)
k = k + 1
c(k) = j
End If
End If
End If
Next j
If sum1 <> 100 Then
For j = 1 To k
Cells(c(j), 59).Interior.Color = RGB(255, 0, 0)
Next j
End If
End If
End If
Next i
Application.EnableEvents = True
End Sub
code adapted, if you want to link it to a button, add a button, right-click on the button and assign this macro (aargh) to it.
Sub aargh()
Dim i As Long, j As Long, sum1 As Long, k As Long, c(5000) As Long, fl(5000) As Boolean
Dim s1 As String, s2 As String
Range("bg5:bg5000").Interior.Color = RGB(255, 255, 255)
For i = 5 To 4999
k = 0
s1 = Cells(i, 4) & Cells(i, 5) & Cells(i, 8) & Cells(i, 36) & Cells(i, 37)
If s1 <> "" Then
If Not fl(i) Then
For j = i + 1 To 5000
If Not fl(j) Then
s2 = Cells(j, 4) & Cells(j, 5) & Cells(j, 8) & Cells(j, 36) & Cells(j, 37)
If s2 <> "" Then
If s1 = s2 Then
If k = 0 Then sum1 = Cells(i, 59): k = 1: c(k) = i: fl(i) = True
sum1 = sum1 + Cells(j, 59)
k = k + 1
c(k) = j
fl(j) = True
End If
End If
End If
Next j
If sum1 <> 100 Then
For j = 1 To k
Cells(c(j), 59).Interior.Color = RGB(255, 0, 0)
Next j
End If
End If
End If
Next i
End Sub

CountIf Application or object defined error

I've got a code that keeps on returning a run-time error 1004 - Application-defined or object-defined error. I've tried stepping through the individual parts of the worksheetfunction.countif function, and they all work fine separately.
However, when I put them together, they fail.
The code is:
s = 2
While Cells(s - 1, 1) <> vbNullString
Rows(s & ":" & s + 3).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range(Cells(s, 1), Cells(s + 3, 1)).Select
Selection.Rows.Group
Cells(s, 1) = "A"
Cells(s + 1, 1) = "B"
Cells(s + 2, 1) = "C"
Cells(s + 3, 1) = "D"
r = 3
q = vbNullString
p = vbNullString
n = s
While n < s + 5
While r <= v
M = 1
If Cells(n, 1) = "A" Then
q = 5
p = 12
ElseIf Cells(n, 1) = "B" Then
q = 18
p = 25
ElseIf Cells(n, 1) = "C" Then
q = 31
p = 38
ElseIf Cells(n, 1) = "D" Then
q = 44
p = 51
End If
While M <= u
l = vbNullString
l = WorksheetFunction.CountIf(Worksheets("IT Teams").Range(Cells(q, M), Cells(p, M)), Worksheets("Players IT").Cells(s + 4, 1))
If Not IsError(l) Then
Cells(n, r) = l
Else
Cells(n, r) = vbNullString
End If
M = M + 5
r = r + 1
Wend
Wend
n = n + 1
r = 3
Wend
s = s + 5
Wend
All variables have been declared as Variants.
Edit: for clarity. Error occurs at:
l = WorksheetFunction.CountIf(Worksheets("IT Teams").Range(Cells(q, M), Cells(p, M)), Worksheets("Players IT").Cells(s + 4, 1))
The problem is the way you declare the ranges. You should always include the sheet, otherwise you get this error, if you use more than one sheet (or if you use one, but it is not the active one).
Like this:
With ActiveSheet
While Cells(s - 1, 1) <> vbNullString
.Rows(s & ":" & s + 3).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
.Range(.Cells(s, 1), .Cells(s + 3, 1)).Select
Selection.Rows.Group
.Cells(s, 1) = "A"
.Cells(s + 1, 1) = "B"
.Cells(s + 2, 1) = "C"
.Cells(s + 3, 1) = "D"
Wend
End With
Pay attention to the dots.
In general, declare the sheets and then use them:
'Option Explicit - start using option explicit
Sub test()
Dim wksA As Worksheet
Dim wksIT As Worksheet
Set wksA = ThisWorkbook.ActiveSheet
Set wksIT = ThisWorkbook.Worksheets("IT Teams")
s = 2
While Cells(s - 1, 1) <> vbNullString
wksA.Rows(s & ":" & s + 3).Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
wksA.Range(wksA.Cells(s, 1), wksA.Cells(s + 3, 1)).Select
Selection.Rows.Group
wksA.Cells(s, 1) = "A"
wksA.Cells(s + 1, 1) = "B"
wksA.Cells(s + 2, 1) = "C"
wksA.Cells(s + 3, 1) = "D"
Wend
With wksIT
While M <= u
l = vbNullString
l = WorksheetFunction.CountIf(.Range(.Cells(q, M), _
.Cells(p, M)), .Cells(s + 4, 1))
If Not IsError(l) Then
.Cells(n, r) = l
Else
.Cells(n, r) = vbNullString
End If
M = M + 5
r = r + 1
Wend
End With
End Sub
Concerning your case, I am about 80% sure, that you get the error somewhere here:
l = WorksheetFunction.CountIf(Range(Cells(q, M), Cells(p, M)), Cells(s + 4, 1))
In general, never assume which worksheet your code is operating on and explicitly define it in your code.
Concerning the place where you get the error, it should be simply like this:
Set wksA = ThisWorkbook.ActiveSheet
Set wksIT = ThisWorkbook.Worksheets("IT Teams")
Set wksPl = ThisWorkbook.Worksheets("SomePlayers")
l = WorksheetFunction.CountIf(wksIT.Range(wksIT.Cells(q, M), wksIT.Cells(p, M)), _
wksPl.Cells(s + 4, 1))

runtime error accured when I run a VBA script to create a simple report out of text output in blocks

Sub blockofdatatoreport()
Dim i As Integer
Dim x As Integer
Dim y As Integer
For i = 1 To 95
actvrw = Sheet1.Range("A:A").Find(what = i, searchdirection = xlNext).Row
'searching cells top to bottom
lr = Sheet2.Range("A:A").Find(what = "*", searchdirection = xlprevious).Row + 1
'searching cells bottom to top
For x = 1 To 5
Sheet2.Cells(lr, 1).Value = Sheet1.Cells(actvrw + (x - 1), 3).Value
'looping the first five columns in sheet2
Next
For y = 1 To 4
Sheet2.Cells(lr, 5 + y).Value = Sheet1.Cells(actvrw + (y - 1), 6).Value
'looping the next four columns after the first four is done in sheet2
Next
'You can also write like this or write a loop in two lines above.
'Sheet2.Cells(lr, 1).Value = Sheet1.Cells(actvrw, 3).Value
'Sheet2.Cells(lr, 2).Value = Sheet1.Cells(actvrw + 1, 3).Value
'Sheet2.Cells(lr, 3).Value = Sheet1.Cells(actvrw + 2, 3).Value
'Sheet2.Cells(lr, 4).Value = Sheet1.Cells(actvrw + 3, 3).Value
'Sheet2.Cells(lr, 5).Value = Sheet1.Cells(actvrw + 4, 3).Value
Next
End Sub
I get error called error 13 y type mismatch, what is in the above code causing the error??

Manipulate a listbox of 11 columns

I've got a listbox of 11 columns. When I try to add data to one of the columns, I get an error.
ListBox1.Column(10, j) = shtG.Cells(k, 13)
I don't understand why this happens, the listbox on the userform has a ColumnCount of 11.
The error I'm getting:
"Run-time error 380: Unable to set Column property. Invalid property value."
The value of the selected cell is "Group 16".
More info:
Code:
'adding this doesn't help
ListBox1.Clear
ListBox1.ColumnCount = 20
While shtG.Cells(k, 1) <> ""
If 'some long working condition Then
frmTP.ListBox1.AddItem (shtG.Cells(k, kolID))
frmTP.ListBox1.Column(1, j) = shtG.Cells(k, kolVnm) & strSpace & shtG.Cells(k, kolTV) & strSpace & shtG.Cells(k, kolAnm)
frmTP.ListBox1.Column(2, j) = shtG.Cells(k, 5)
frmTP.ListBox1.Column(3, j) = shtG.Cells(k, 6)
frmTP.ListBox1.Column(4, j) = shtG.Cells(k, 7)
frmTP.ListBox1.Column(5, j) = shtG.Cells(k, 8)
frmTP.ListBox1.Column(6, j) = shtG.Cells(k, 9)
frmTP.ListBox1.Column(7, j) = shtG.Cells(k, 10)
frmTP.ListBox1.Column(8, j) = shtG.Cells(k, 11)
frmTP.ListBox1.Column(9, j) = shtG.Cells(k, 12)
frmTP.ListBox1.Column(10, j) = shtG.Cells(k, 13)
j = j + 1
End If
k = k + 1
Wend
This is the sort of thing I mean (you could improve performance by loading the sheet data into an array to begin and processing that, and not resizing the array so often, but it would distract from the key idea here!):
Dim vData()
j = 0
While shtG.Cells(k, 1) <> ""
If 'some long working condition Then
ReDim Preserve vData(0 To 10, 0 To j)
vData(0, j) = shtG.Cells(k, kolID).Value
vData(1, j) = shtG.Cells(k, kolVnm) & strSpace & shtG.Cells(k, kolTV) & strSpace & shtG.Cells(k, kolAnm)
vData(2, j) = shtG.Cells(k, 5)
vData(3, j) = shtG.Cells(k, 6)
vData(4, j) = shtG.Cells(k, 7)
vData(5, j) = shtG.Cells(k, 8)
vData(6, j) = shtG.Cells(k, 9)
vData(7, j) = shtG.Cells(k, 10)
vData(8, j) = shtG.Cells(k, 11)
vData(9, j) = shtG.Cells(k, 12)
vData(10, j) = shtG.Cells(k, 13)
j = j + 1
End If
Wend
frmTP.ListBox1.Column = vData

Excel Search VBA macro

I have been given the task of searching through a large volume of
data. The data is presented identically across around 50 worksheets. I
need a macro which searches through all these sheets for specific
values then copies certain cells to a table created in a new workbook.
The macro also needs to create the table headings when it is run.
It must Search column G For the Value 9.1 Then certain information
must be copied to corresponding columns in the table
FHA Ref = Same row value from column G
Engine Effect = Same row value from column F
Part Number = Always cell J3
Part Name = Always cell C2
FM ID = Same Row value from Column B
Failure Mode & Cause = Same Row Value from Column C
FMCN = Same Row Value From Column C"`
If it is a hassle to create the new workbook with these column
headings then I would be quite happy to create the headings myself in
the worksheet and just have the macro search for and copy the data to
the rows corresponding to the headings.
If any help or backup files are needed I would be more than happy to
provide these.
the code I have at the moment is based on a userform also ideally I would do away with this and just search all sheets
Public Sub createWSheet(module, srcWBook)
Dim i
i = 0
srcWB = srcWBook
For Each ws In Workbooks(srcWBook).Worksheets
i = i + 1
If ws.Name = module Then
MsgBox ("A worksheet with for this module already exists")
Exit Sub
End If
Next ws
Workbooks(srcWBook).Activate
Worksheets.Add after:=Worksheets(i)
ActiveSheet.Name = module
Cells(2, 2) = "FHA Ref"
Cells(2, 3) = "Engine Effect"
Cells(2, 4) = "Part No"
Cells(2, 5) = "Part Name"
Cells(2, 6) = "FM ID"
Cells(2, 7) = "Failure Mode & Cause"
Cells(2, 8) = "FMCN"
Cells(2, 9) = "PTR"
Cells(2, 10) = "ETR"
Range(Cells(2, 2), Cells(2, 10)).Font.Bold = True
Range(Cells(1, 2), Cells(1, 10)) = "Interface"
Range(Cells(1, 2), Cells(1, 10)).MergeCells = True
Range(Cells(1, 2), Cells(1, 10)).Font.Bold = True
Workbooks(srcWBook).Activate
End Sub
Dim mainWB, srcWBook
Dim headerLeft, headerTop, headerBottom, headerRight
Dim nTargetFMECA, nPartID, nLineID, nPartNo, nPartName, nQTY, nFailureMode, nAssumedSystemEffect, nAssumedEngineEffect
Dim item As String
Dim mDest
Dim selections(100)
Public Sub controlCopyFMs(mWB, sWB, module)
Dim i
mainWB = mWB
srcWBook = sWB
mDest = 2
nTargetFMECA = 0
nPartID = 0
nLineID = 0
nPartNo = 0
nPartName = 0
nQTY = 0
nFailureMode = 0
nAssumedSystemEffect = 0
nAssumedEngineEffect = 0
For i = 0 To TestForm.LBSelected.ListCount - 1
Call copyFMs(module, selections(i))
Next i
End Sub
Public Sub copyFMs(module, comp)
Dim mSrc
Workbooks(srcWBook).Sheets(comp).Select
If exploreHeader(comp) = 0 Then
Exit Sub
End If
mSrc = headerBottom + 3
While Cells(mSrc, nSrc).Text <> ""
If Cells(mSrc, nIndication).Text <> "-" Then
If Cells(mSrc, nIndication).Text <> "" Then
Workbooks(mainWB).Worksheets(module).Cells(mDest, 2) = Cells(mSrc, nTargetFMECA).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 3) = Cells(mSrc, nPartID).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 4) = Cells(mSrc, nLineID).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 5) = Cells(mSrc, nPartNo).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 6) = Cells(mSrc, nPartName).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 7) = Cells(mSrc, nQTY).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 8) = Cells(mSrc, nFailureMode).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 9) = Cells(mSrc, nAssumedEngineEffect).Value
Workbooks(mainWB).Worksheets(module).Cells(mDest, 10) = Cells(mSrc, nAssumedSystemEffect).Value
mDest = mDest + 1
End If
End If
mSrc = mSrc + 2
Wend
End Sub
Public Function exploreHeader(comp)
Dim m, n
m = 1
n = 1
While ((InStr(1, Cells(m, n).Text, "Engine Programme:", vbTextCompare) <= 0) Or (InStr(1, Cells(m, n).Text, "BR700-725", vbTextCompare) <= 0)) And n < 10
If m < 10 Then
m = m + 1
Else
n = n + 1
m = 1
End If
Wend
headerTop = m
headerLeft = n
While StrComp(Cells(m, n).Text, "ID", vbTextCompare) <> 0 And StrComp(Cells(m, n).Text, "Case No.", vbTextCompare) <> 0
m = m + 1
Wend
headerBottom = m - 1
While Cells(m, n).Borders(xlEdgeBottom).LineStyle = xlContinuous
n = n + 1
Wend
headerRight = n - 1
m = headerTop
n = headerLeft
Do
If n > headerRight Then
n = headerLeft
m = m + 1
End If
If InStr(1, Cells(m, n).Value, "Item No.:", vbTextCompare) > 0 Then
item = Right(Cells(m, n).Value, Len(Cells(m, n).Value) - InStr(1, Cells(m, n).Value, ":", vbTextCompare))
Cells(m, n).Select
Exit Do
End If
n = n + 1
Loop While m <= headerBottom
m = headerBottom + 1
n = headerLeft
While n <= headerRight
If StrComp(Cells(m, n).Value, "ID", vbTextCompare) = 0 Then
nID = n
End If
If StrComp(Cells(m, n).Value, "Mitigation", vbTextCompare) = 0 Then
nMitigation = n
End If
If StrComp(Cells(m, n).Value, "Remarks", vbTextCompare) = 0 Then
nRemarks = n
End If
If StrComp(Cells(m, n).Value, "FMCN", vbTextCompare) = 0 Then
nFMCN = n
End If
If StrComp(Cells(m, n).Value, "Indication", vbTextCompare) = 0 Then
nIndication = n
End If
If StrComp(Cells(m, n).Value, "Crit", vbTextCompare) = 0 Then
nFMCN = n
End If
If StrComp(Cells(m, n).Value, "Detect", vbTextCompare) = 0 Then
nIndication = n
End If
If StrComp(Cells(m, n).Value, "Functional Description", vbTextCompare) = 0 Then
nMitigation = n
End If
n = n + 1
Wend
exploreHeader = 1
End Function
Public Sub initSelections()
For i = 0 To 99
selections(i) = ""
Next i
End Sub
Public Sub loadSelection(comp, i)
selections(i) = comp
End Sub
Public Sub deleteSelection(i)
While selections(i) <> ""
selections(i) = selections(i + 1)
i = i + 1
Wend
End Sub
I hope this can help more. This code may not work 100% but it should be good enough to guide you. Let me know if you have questions.
Dim WS As Worksheet
Dim Results(7, 1000000) As String ''Didn't know what is a good data type or how many possible results
Dim ColValue() As Variant
Dim I, II, ResultCt As Long
ResultCt = 0
For Each WS In ActiveWorkbook.Worksheets ''This should get all your result and information into the Results Array
ColValue = ActiveSheet.Range(Cells(2, 7), Cells(WS.UsedRange.Rows.Count, 7)).Value ''This put all of column G into an array
For I = 0 To UBound(ColValue)
If ColValue(I, 1) = "9.1" Then
Results(0, ResultCt) = Cells(I + 1, 7).Value ''I think it is off by 1, but if not remove the +1
Results(1, ResultCt) = Cells(I + 1, 6).Value
Results(2, ResultCt) = Cells(3, 10).Value
Results(3, ResultCt) = Cells(2, 3).Value
Results(4, ResultCt) = Cells(I + 1, 2).Value
Results(5, ResultCt) = Cells(I + 1, 3).Value
Results(6, ResultCt) = Cells(I + 1, 3).Value
ResultCt = ResultCt + 1
End If
Next
Next WS
''At this point us your code to create the worksheet and name it
''starting from the line Workbooks(srcWBook).Activate
''Then Set the Active cell to where ever you want to start putting the data and have something like
For I = 0 To UBound(Results, 2)
For II = 0 To UBound(Results)
ActiveCell.Offset(I, II).Value = Results(I, II) ''This assumes you put the information into Result in the order you want it printed out
Next
Next