LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Help enclosing a macro in With/End With

I wrote the following macro in XL and it works fine. The problem
is that I want to run it from another program (SPSS). In an example
I saw in SPSS the code was enclosed in a With/End Loop:

'GetObject returns a reference to an existing app.
Set objExcelApp = GetObject(,"Excel.Application")
With objExcelApp

tablenb = tablenb +1
line1 = .Selection.Row
line2 = .Selection.Rows(.Selection.Rows.Count).Row
col1 = .Selection.Column
col2 = .Selection.Columns(.Selection.Columns.Count).Colum n
' Add a table number in the first line, make title bold & blue
.Cells(line1, col1)= "Table" & Str(tablenb) & " " & .Cells(line1, col1)
.cells(line1,col1).font.bold=True
.cells(line1,col1).Font.ColorIndex = 5
'Select the table lines (except the title) and group the lines
'.Range(.Cells(line1 + 1, col1), .Cells(line2 + 2, col2)).Select
'.Selection.Rows.Group
End With


The difference appears to be that a lot of the commands within the
With statement have periods before them. As you can probably tell
from my language I am not a programmer. I just try to simplify my
work with macros whenever possible. I have absolutely no idea
how to do change this and was wondering if someone could help?

Lance





Sub Strip_Discrim()

Application.ScreenUpdating = False
'find the current set of discrim tables by seaching for line that reads
'table 1, everything before this should be already formated lines
Cells.Find(What:="Table 1 Classification Function Coefficients", After:= _
ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, _ SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Activate
startrow = ActiveCell.Row


ActiveCell.SpecialCells(xlLastCell).Select 'Find the last used cell in spreadsheet
LastCell = ActiveCell.Row 'Name LastRow as the number value of the row
Do While LastCell (startrow - 1)
Rows(LastCell).Select

If Cells(LastCell, 1).Value = "" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = " " Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "Original" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "(Constant)" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "Table 1 Classification Function Coefficients" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "Table 2 Classification Results(a)" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "Fisher's linear discriminant functions" Then
Selection.EntireRow.Delete
ElseIf Cells(LastCell, 1).Value = "a" Then
Cells(LastCell, 1).Select
Selection.Delete Shift:=xlToLeft
End If

LastCell = LastCell - 1
Loop

Columns("A:A").Select
Selection.Replace What:=" of original grouped cases correctly classified.", _
Replacement:="", LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:= _
False, SearchFormat:=False, ReplaceFormat:=False

Application.ScreenUpdating = True

' Need to delete only current table cells leaving rest intact
ActiveCell.SpecialCells(xlLastCell).Select 'Find the last used cell in spreadsheet
LastCell2 = ActiveCell.Row 'Name LastRow as the number value of the row

' Range(Cells(I, j + 1), Cells(I, LastCol)).Clear
Range(Cells(startrow, 2), Cells(LastCell2, 24)).Select
Selection.ClearContents

'Now, transpose values
ActiveCell.SpecialCells(xlLastCell).Select 'Find the last used cell in spreadsheet
lastcell3 = ActiveCell.Row 'Name LastRow as the number value of the row

Range(Cells(startrow, 1), Cells(lastcell3, 1)).Select
Selection.Copy
Cells(lastcell3 + 1, 1).Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True

'Now, delete everything between startcell and final transposed values

Range(Cells(startrow, 1), Cells(lastcell3, 1)).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete


End Sub

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro recorded... tabs & file names changed, macro hangs Steve Excel Worksheet Functions 3 October 30th 09 11:41 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
how to count/sum by function/macro to get the number of record to do copy/paste in macro tango Excel Programming 1 October 15th 04 01:16 PM
Enclosing values in Quotation marks bypass Excel Programming 3 June 11th 04 05:16 PM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 05:28 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"