Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Macro recorded... tabs & file names changed, macro hangs | Excel Worksheet Functions | |||
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort | Excel Worksheet Functions | |||
how to count/sum by function/macro to get the number of record to do copy/paste in macro | Excel Programming | |||
Enclosing values in Quotation marks | Excel Programming | |||
Start Macro / Stop Macro / Restart Macro | Excel Programming |