Vba macro modification

FGaxha

Board Regular
Joined
Jan 10, 2023
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi Masters,
I have a macro coded : It copy all values <=12 in V2, and also name “James” on column 20 and “OES” on column 10.
It create a new tab with name “James” for all “OES” if V2 less then 12.
I need to have a second macros that does same search for the same names but instead of “OES” to look for “OE” and name new tab “James-OE”
Thank you:

VBA Code:
Sub TestTim()
test3 "OES", "Tim"
End Sub

Sub TestGeorge()
test3 "OES", "George"
End Sub

Sub test3(Category As String, FirstName As String)
Dim outarr()
Dim inarr As Variant, indi As Long, I As Long, J As Long                                 '<<<< missing variable declarations.

inarr = Range("A1:V7500").Value
ReDim outarr(1 To 7500, 1 To 22)
indi = 1
For I = 2 To 7500
If UCase(inarr(I, 10)) = UCase(Category) And UCase(inarr(I, 20)) = UCase(FirstName) And inarr(I, 22) <= 12 Then
' copy row
For J = 1 To 22
outarr(indi, J) = inarr(I, J)
Next J
indi = indi + 1
End If
Next I
Worksheets.Add
ActiveSheet.Name = FirstName
If indi > 1 Then
Range(Cells(1, 1), Cells(indi - 1, 22)) = outarr
End If
End Sub
 
Last edited by a moderator:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Do you mean?
VBA Code:
Sub TestTim()
test3 "OE", "James"
End Sub
 
Upvote 0
Sorry, my fault.

I want to use a second Macro" as well to extract data same range but different description.

test3"OE","Tim_OE"
test3"OE","George_OE"

Also new Tab to be renamed Tim_OE when i run Tim-OE macro. Same when I run George_OE macro.



Sub TestTim()
test3 "OES", "Tim"
End Sub

Sub TestGeorge()
test3 "OES", "George"
End Sub

Sub test3(Category As String, FirstName As String)
Dim outarr()
Dim inarr As Variant, indi As Long, I As Long, J As Long '<<<< missing variable declarations.

inarr = Range("A1:V7500").Value
ReDim outarr(1 To 7500, 1 To 22)
indi = 1
For I = 2 To 7500
If UCase(inarr(I, 10)) = UCase(Category) And UCase(inarr(I, 20)) = UCase(FirstName) And inarr(I, 22) <= 12 Then
' copy row
For J = 1 To 22
outarr(indi, J) = inarr(I, J)
Next J
indi = indi + 1
End If
Next I
Worksheets.Add
ActiveSheet.Name = FirstName
If indi > 1 Then
Range(Cells(1, 1), Cells(indi - 1, 22)) = outarr
End If
End Sub
 
Upvote 0
How about

VBA Code:
Sub TestTim()
test3 "OES", "Tim"
test3"OE","Tim_OE"
End Sub

Sub TestGeorge()
test3 "OES", "George"
test3"OE","George_OE"
End Sub
 
Upvote 0
Hi Nemmi69,
Thank you for your reply.
The issue is here:
This macro is searching based on two criteria.
“OES” and “Tim” so if I change “Tim_OE” it rename new Tam “Tim_OE” but is not picking up anything, because column T, Ucade(insrr,(I 20 ))
Column T has only name Tim.
So: search for OES and Tim, rename Tab Tim.
Search for OE and Tim , rename Tab Tim_OE

Sub TestTim()
test3 "OES", "Tim"
test3"OE","Tim_OE"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,101
Messages
6,123,095
Members
449,095
Latest member
gwguy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top