Macro involving multiple sheet and files

dguenther

Board Regular
Joined
Jun 15, 2011
Messages
75
Hello,

I am new to this forum, but I have familiarity with Excel, and some familiarity with VBA and macros.

I'll try to explain my project succinctly.

(1) I am going to have a lot of .xlsm files that were recently converted from .txt

(2) Each of these .xlsm files will have a good deal of data in them, some extraneous, some important. It is all actually legal text. I want to cut out all junk and just keep the good stuff.

(3) I'm doing my best, but I need some help!

Here's what a typical file looks like:

1 of 26 DOCUMENTS

In re Phillips

Arizona Supreme Court No. SB-10-0036-D

SUPREME COURT OF ARIZONA

244 P.3d 549; 2010 Ariz. LEXIS 52; 597 Ariz. Adv. Rep. 19


December 16, 2010, Decided



DISPOSITION:*Disciplinary Action from the Disciplinary Commission SUSPENSION AND
PROBATION ORDERED.

CASE SUMMARY:


PROCEDURAL POSTURE: Respondent attorney argued that the Hearing Officer
erroneously used a vicarious.....

OVERVIEW: The attorney argued that the Hearing Officer used an improper standard
of vicarious liability in finding violations of Ariz. R. Prof. Conduct 5.1(a)
and 5.3(a) .........

OUTCOME: The recommended length of the attorney's suspension was modified to six
months, and all other recommendations were accepted.

JUDGES:

***... [**1] John Pelander, Justice. CONCURRING: Rebecca White Berch, Chief
Justice, Andrew D. Hurwitz, Vice Chief Justice, Jon W. Thompson, Judge.
WEISBERG, Judge, concurring in part and dissenting in part....




I want it to look like:
Herring v. Herring + No. 10-017 + 2011 VT 38; 2011 Vt. LEXIS 48 +May 5, 2011, Filed +Present: Reiber, C.J., Dooley, Johnson, Skoglund and Burgess, JJ.REIBER, C.J., dissenting....
with + signifying a new cell, but I want them all to be on the same row.

****
Now, I have written a series of macros that made the transformations I wanted. But, it only works on that exact file and group of text, not on another similar but distinct file.

Here are the macros:

Sub trialuptojudge()
'
' trialuptojudge Macro
'

'
Sheets.Add
Sheets("VT_State_Cases,_Combined2011-06").Select
Sheets("VT_State_Cases,_Combined2011-06").Move Before:=Sheets(1)
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:2").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("B1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:4").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("C1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("D1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
End Sub
Sub findjudge()
'
' findjudge Macro
'

'
Cells.Find(What:="judge", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range("A43:A44").Select
Selection.Cut
Sheets("Sheet1").Select
Range("H1").Select
ActiveSheet.Paste
End Sub
Sub concatenate()
'
' concatenate Macro
'

'
Range("E1").Select
Columns("D:D").EntireColumn.AutoFit
Range("F1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[2],R[1]C[2])"
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F1:N2").Select
Application.CutCopyMode = False
Selection.ClearContents
End Sub

****
So, it seems like the first major problem I am encountering is my second step where I select sheet "VT_State_Cases,_Combined2011-06". The next time I try to run it on a different file, it's not called that obviously, and Excel yells at me with a run-time error 9 subscript out of range

Any help on that first step?

Thanks so much and tell me anything more that I could post that would help you help me!

Sincerely,
dguenther
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
{Edit 6/15/2011}

Here is the code more nicely shown:

Code:
Sub trialuptojudge()
'
' trialuptojudge Macro
'

'
Sheets.Add
Sheets("VT_State_Cases,_Combined2011-06").Select
Sheets("VT_State_Cases,_Combined2011-06").Move Before:=Sheets(1)
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:2").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("B1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:4").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("C1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
Rows("1:3").Select
Selection.Delete Shift:=xlUp
Range("A1").Select
Selection.Cut
Sheets("Sheet1").Select
Range("D1").Select
ActiveSheet.Paste
Sheets("VT_State_Cases,_Combined2011-06").Select
End Sub
Sub findjudge()
'
' findjudge Macro
'

'
Cells.Find(What:="judge", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Activate
Range("A43:A44").Select
Selection.Cut
Sheets("Sheet1").Select
Range("H1").Select
ActiveSheet.Paste
End Sub
Sub concatenate()
'
' concatenate Macro
'

'
Range("E1").Select
Columns("D:D").EntireColumn.AutoFit
Range("F1").Select
ActiveCell.FormulaR1C1 = "=CONCATENATE(RC[2],R[1]C[2])"
Selection.Copy
Range("E1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F1:N2").Select
Application.CutCopyMode = False
Selection.ClearContents
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
Members
452,902
Latest member
Knuddeluff

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