Find and copy

nasir

Board Regular
Joined
Apr 7, 2006
Messages
124
I need help on VBA that will prompt users to enter numbers, seperated by comas. When the users clicks OK, the vba will copy the data associated with those numbers in different tabs. The name of the tabs will be the numbers entered by the users in the input box


Excel Workbook
ABCD
80100
9Object CategoryGAAP Category TitleComptroller Source GroupComptroller Source Group Title
10PERSONNEL SERVICES0011REGULAR PAY - CONT FULL TIME
110012REGULAR PAY - OTHER
120013ADDITIONAL GROSS PAY
130014FRINGE BENEFITS - CURR PERSONNEL
140015OVERTIME PAY
150099UNKNOWN PAYROLL POSTINGS
16PERSONNEL SERVICES
17NON-PERSONNEL SERVICES0020SUPPLIES AND MATERIALS
180030ENERGY, COMM. AND BLDG RENTALS
190031TELEPHONE, TELEGRAPH, TELEGRAM, ETC
200032RENTALS - LAND AND STRUCTURES
210033JANITORIAL SERVICES
220034SECURITY SERVICES
230035OCCUPANCY FIXED COSTS
240040OTHER SERVICES AND CHARGES
250041CONTRACTUAL SERVICES - OTHER
260070EQUIPMENT & EQUIPMENT RENTAL
27NON-PERSONNEL SERVICES
280100
291359
30Object CategoryGAAP Category TitleComptroller Source GroupComptroller Source Group Title
3101PERSONNEL SERVICES0011REGULAR PAY - CONT FULL TIME
320012REGULAR PAY - OTHER
330013ADDITIONAL GROSS PAY
340014FRINGE BENEFITS - CURR PERSONNEL
350015OVERTIME PAY
360099UNKNOWN PAYROLL POSTINGS
37PERSONNEL SERVICES
3802NON-PERSONNEL SERVICES0020SUPPLIES AND MATERIALS
390031TELEPHONE, TELEGRAPH, TELEGRAM, ETC
400032RENTALS - LAND AND STRUCTURES
410035OCCUPANCY FIXED COSTS
420040OTHER SERVICES AND CHARGES
430041CONTRACTUAL SERVICES - OTHER
440070EQUIPMENT & EQUIPMENT RENTAL
45NON-PERSONNEL SERVICES
461359
Page1_1


If the user enters 0100, then the vba will copy:
Excel Workbook
ABCDEFG
80100
9Object CategoryGAAP Category TitleComptroller Source GroupComptroller Source Group TitleAppropriationCurrent AY Expenditure (Less I-D Adv)
10PERSONNEL SERVICES0011REGULAR PAY - CONT FULL TIME2,879,1131,544,694
110012REGULAR PAY - OTHER96,7381,061,947
120013ADDITIONAL GROSS PAY0106,467
130014FRINGE BENEFITS - CURR PERSONNEL544,563494,668
140015OVERTIME PAY300,00083,043
150099UNKNOWN PAYROLL POSTINGS00
16PERSONNEL SERVICES3,820,4143,290,820
17NON-PERSONNEL SERVICES0020SUPPLIES AND MATERIALS155,00085,467
180030ENERGY, COMM. AND BLDG RENTALS4,765,5365,671,744
190031TELEPHONE, TELEGRAPH, TELEGRAM, ETC97,355111,026
200032RENTALS - LAND AND STRUCTURES9,350,7845,863,092
210033JANITORIAL SERVICES203,618142,176
220034SECURITY SERVICES1,590,686530,096
230035OCCUPANCY FIXED COSTS1,179,726617,718
240040OTHER SERVICES AND CHARGES1,981,629994,643
250041CONTRACTUAL SERVICES - OTHER4,595,796392,932
260070EQUIPMENT & EQUIPMENT RENTAL240,00025,229
27NON-PERSONNEL SERVICES24,160,12914,434,123
28010027,980,54317,724,943
Page1_1



Thanks
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
I found the following VBA but needs to be tweaked. Any help appreciated.

Thanks
Nasir
 
Upvote 0
Oopes, forget the code:
'=====================================================
'- FIND & COPY
'- Brian Baulsom January 2005
'=====================================================
Sub FindHiLight()
Dim MyFind As Variant
Dim MyNewValue As Variant
Dim FoundCell As Object
Dim Counter As Long
'-------------------------------------------------
'- SET SEARCH KEY
MyFind = InputBox("Please insert value to find.")
If MyFind = "" Then End
Counter = 0
'------------------------------------------------ I also want to tweak here so that user can enter multiple number like 0100,1456,1460 etc
'- FIND ALL MATCHING CELLS
On Error Resume Next
Set ws = ActiveSheet
Set FoundCell = ws.Cells.Find(What:=MyFind)
If Not FoundCell Is Nothing Then
FirstAddress = FoundCell.Address
Do
Counter = Counter + 1
'--------------------------------------------
'- what to do if found
Application.ScreenUpdating = False
'Here I need to copy all rows where the number user entered begins and ends


FoundCell.Interior.ColorIndex = 16
'--------------------------------------------
Set FoundCell = ws.Cells.FindNext(FoundCell)
Loop While Not FoundCell Is Nothing _
And FoundCell.Address <> FirstAddress
End If
rsp = MsgBox("Found " & Counter)
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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