Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it
in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Maybe...
Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Both of them are giving me Compile error: User-defined type not defined
and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Typo...
Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Unfortunately neither one of those worked. the original script works
perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel doesn't have an activedocument.
Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
:-) here is an example of what i am trying to do:
DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
So what happens with the cells/rows with "Vocabulario en acción 1" on them?
Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
leaving (A:M, and N:IV alone)
should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
It works awesome, thank you so much. :-)
God bless jsd219 PS. yes i wanted to delete the entire row Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#11
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Question: i have run into a snag, i found some discrepancies with my
spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#12
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Option Explicit
Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#13
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
works perfect, i can't thank you enough. :-)
God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate.... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an.... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat.... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#14
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Well, once we got rid of that awful MSWord stuff, it was pretty much clear
sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#15
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
OK, first of all if you are tired of messing with me i understand and i
appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#16
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
You have a difference in what you write and the "after" sample.
You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#17
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sorry for the delay, you are correct i should have wrote "Cultura" not
"CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information.... x Cultura x Communication 1.3 Students present information.... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further.... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate.... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N")..End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#18
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't understand why the columns can't be used. If there are things between
those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#19
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
i sent a part of the spread sheet to your email address. i just want to
make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1..1 Students... x Gramática en acción 1 - Communication 1..2 Students... x Gramática en acción 1 - Communication 1..3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell..Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret.... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret.... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#20
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't open unsolicited files.
jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#21
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
ok, here is a sample of my spread sheet: Notice there are multiple
items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1.1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1)..Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next..Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#22
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Untested:
Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") _ And (LCase(myCell.Value) Like sStart & "*") _ Or (LCase(myCell.Value) Like sEnd & "*") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: ok, here is a sample of my spread sheet: Notice there are multiple items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1.1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#23
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I got it to work by changing
from: Set myRng =.Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) to: Set myRng = Selection but i have lost the ability to input a string of text in an input box for the beginning and input another string of text in an input box for the end God bless jsd219 Dave Peterson wrote: Untested: Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") _ And (LCase(myCell.Value) Like sStart & "*") _ Or (LCase(myCell.Value) Like sEnd & "*") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: ok, here is a sample of my spread sheet: Notice there are multiple items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information.... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1.1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows..Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked.. the original script works perfectly in word but my work is in excel.. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument..Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#24
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
replace these lines:
sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") with: sStart = lcase(InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING")) If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = lcase(InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION")) If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If From one of those other posts. jsd219 wrote: I got it to work by changing from: Set myRng =.Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) to: Set myRng = Selection but i have lost the ability to input a string of text in an input box for the beginning and input another string of text in an input box for the end God bless jsd219 Dave Peterson wrote: Untested: Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") _ And (LCase(myCell.Value) Like sStart & "*") _ Or (LCase(myCell.Value) Like sEnd & "*") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: ok, here is a sample of my spread sheet: Notice there are multiple items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1.1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#25
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I did not work. it deleted several rows that should not have been
deleted. i can work with just selecting the sections. i don't want to bother you anymore with this, i really appreciate everything you have done. God bless jsd219 PS. is there a way to have VBA open a PDF document select the contents and paste them into an excel spread sheet? Dave Peterson wrote: replace these lines: sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") with: sStart = lcase(InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING")) If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = lcase(InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION")) If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If From one of those other posts. jsd219 wrote: I got it to work by changing from: Set myRng =.Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) to: Set myRng = Selection but i have lost the ability to input a string of text in an input box for the beginning and input another string of text in an input box for the end God bless jsd219 Dave Peterson wrote: Untested: Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") _ And (LCase(myCell.Value) Like sStart & "*") _ Or (LCase(myCell.Value) Like sEnd & "*") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: ok, here is a sample of my spread sheet: Notice there are multiple items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions.... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1..1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2.... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4..1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4..2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1)..Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy..Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#26
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
One more to try (and tested):
Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column sStart = LCase(InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING")) If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = LCase(InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION")) If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If (LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x")) _ And (LCase(myCell.Value) Like sStart & "*") Then bReplace = True ElseIf (LCase(.Cells(myCell.Row, TurnOnOffCol).Value) _ = LCase("x")) _ And (LCase(myCell.Value) Like sEnd & "*") Then bReplace = False ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") _ And bReplace = True Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else RngToDelete.EntireRow.Delete End If End Sub jsd219 wrote: I did not work. it deleted several rows that should not have been deleted. i can work with just selecting the sections. i don't want to bother you anymore with this, i really appreciate everything you have done. God bless jsd219 PS. is there a way to have VBA open a PDF document select the contents and paste them into an excel spread sheet? Dave Peterson wrote: replace these lines: sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") with: sStart = lcase(InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING")) If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = lcase(InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION")) If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If From one of those other posts. jsd219 wrote: I got it to work by changing from: Set myRng =.Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) to: Set myRng = Selection but i have lost the ability to input a string of text in an input box for the beginning and input another string of text in an input box for the end God bless jsd219 Dave Peterson wrote: Untested: Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Dim sStart As String Dim sEnd As String Set wks = ActiveSheet sStart = LCase("STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = LCase("CORE INSTRUCTION") With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") _ And (LCase(myCell.Value) Like sStart & "*") _ Or (LCase(myCell.Value) Like sEnd & "*") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: ok, here is a sample of my spread sheet: Notice there are multiple items in the same columns and this is only one section of the sheet. there are several sections and each section has variations. I only need to make adjustments between "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION". the great thing about being able to select my sStart and sEnd is other sheets might need adjustments in other parts of the sheet. i.e. "OPTIONAL RESOURCES" and "PRACTICE OPTIONS" BLOCK 2 x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Vocabulario en acción 1 x Communication 1.1 Students engage in conversations... x Communication 1.2 Students understand and... x Communication 1.3 Students present information... x Gramática en acción 1 x Communication 1.2 Students understand and... x Comparisons 4.1 Students demonstrate underst... x Comparisons 4.2 Students demonstrate underst.... x CORE INSTRUCTION x Warm -Up x · (5 min.) See Bell Work 1.2 p. 10. 1.2 x Vocabulario en acción 1 x · (15 min.) Present ¡Exprésate! and... x · (5 min.) Have students do... x · (5 min.) Play Audio CD 1, Tr. 3 for... x · (15 min.) Have students do ... x · (5 min.) Present Nota cultural... x · (5 min.) Show GramaVisión.... x · (10 min.) Present Gramática using... x · (15 min.) Have students do Activities... x · (8 min.) Have students use expressions... x Wrap -Up x · (2 min.) See Heritage Speakers, p. 14. x OPTIONAL RESOURCES x Suggestions and Activities x · (10 min.) Comunicación (TE), p. 11. 1.1 x · (10 min.) Advanced Learners, p. 11. 1.1 x · (5 min.) For linguistic learners see... x · (5 min.) For Activity 15 see Slower... x · (5 min.) For Activity 15 for students... x PRACTICE OPTIONS x · Lab Book, pp. 13-14, 56 x · Cuaderno de vocabulario y... x · ¡Exprésate! para hispanohablantes, pp. 4-7 x · Cuaderno de actividades, pp. 1-3 x · Activities for Communication, pp. 1-2, 55-56 x · Teaching Transparencies: Bell Work 1.2... x · Video Guide, pp. 4-5, 6 x · TPR Storytelling Book, pp. x-1 x · Grammar Tutor for Students of... x · Independent Study Guide, p. 1 x · Interactive Tutor (Disc 1) or DVD Tutor (Disc 1) x · Online practice, Chapter 1... BLOCK 3 I did try your code to see if columns-only would work and it made adjustments to several other rows that did not need to be adjusted. God bless jsd219 Dave Peterson wrote: I don't open unsolicited files. jsd219 wrote: i sent a part of the spread sheet to your email address. i just want to make sure you get it. God bless jsd219 Dave Peterson wrote: I don't understand why the columns can't be used. If there are things between those groupings, then they shouldn't have an X in column F. And the the processing (bReplace) should have been toggled off at the end of the "real" group. You can change the columns that are used in this section. TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column jsd219 wrote: Sorry for the delay, you are correct i should have wrote "Cultura" not "CORE INSTRUCTION" It can't run based on columns only for the initial search and find because there are several other items that fall in the same column as "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION" The text is in column "N" but for the sake of this form i pulled alot of columns and info out. the "x" for STANDARDS and CORE are in column "F" (labeled Tier 4). 3 columns: F, G, and H. God bless jsd219 Dave Peterson wrote: You have a difference in what you write and the "after" sample. You write: i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result But you don't delete "Core instruction", you deleted Cultura. And instead of looking for phrases like "STANDARDS FOR FOREIGN LANGUAGE LEARNING" and "CORE INSTRUCTION", it looks like we could just use the X's in the first two columns. Since the text is in column N, I'm gonna guess that the X's are in the previous 3 columns: K, L, and M. X in column K will mean turn on or turn off the processing. X in column L will mean to use that as the prefix string and the X in column M will just hang around. The macro won't touch it. Option Explicit Sub AddTextToCellsExcel3() Dim myCell As Range Dim myRng As Range Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Dim TurnOnOffCol As Long Dim PrefixCol As Long Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) TurnOnOffCol = .Range("K1").Column PrefixCol = .Range("L1").Column bReplace = False For Each myCell In myRng.Cells If LCase(.Cells(myCell.Row, TurnOnOffCol).Value) = LCase("x") Then 'off turns to on 'and on turns to off bReplace = Not bReplace ElseIf LCase(.Cells(myCell.Row, PrefixCol).Value) = LCase("x") Then myStr = myCell.Value & " - " If RngToDelete Is Nothing Then Set RngToDelete = myCell Else Set RngToDelete = Union(myCell, RngToDelete) End If Else If bReplace = True Then myCell.Value = myStr & myCell.Value End If End If Next myCell End With If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 x Communication 1.1 Students engage in conversations, provide... x Communication 1.2 Students understand and interpret.... x Communication 1.3 Students present information... x Cultura x Communication 1.3 Students present information... x Cultures 2.1 Students demonstrate an understanding... x Connections 3.1 Students reinforce and further... x Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION The above is the snag. although the script adjustment works great i have found it still takes some time due to the sixe of the spread sheets. In the case above i need to take "Gramática en acción 1" and paste it in front of the next three rows below. i then need to take "Cultura" and paste it in the cell below until i hit "CORE INSTRUCTION" once that is done i need to delete the original row that held "Gramática en acción 1" and the original row that held "CORE INSTRUCTION" here is the end result: OK, first of all if you are tired of messing with me i understand and i appreciate all of the help you have given me. if you are interested in the next challenge: here it is: x STANDARDS FOR FOREIGN LANGUAGE LEARNING x Gramática en acción 1 - Communication 1.1 Students... x Gramática en acción 1 - Communication 1.2 Students... x Gramática en acción 1 - Communication 1.3 Students... x Cultura - Communication 1.3 Students present information... x Cultura - Cultures 2.1 Students demonstrate an understanding... x Cultura - Connections 3.1 Students reinforce and further... x Cultura - Comparisons 4.1 Students demonstrate... x CORE INSTRUCTION I think this can be done based on the columns to the left with the "x"s. In the top example you will notice three columns of "x"s and notice where the "x" for "Gramática en acción 1" and "CORE INSTRUCTION" fall. OK, :-) can you alter your original script to use the input box for the sStart and sEnd. once it finds the row to copy (based on the sStart) it copies down until it hits a row with an "x' in the same tier. at that point it copies the new cell down until it hits the sEnd (in this case "CORE INSTRUCTION") God bless jsd219 PS. i don't want to be a bother so i do understand if you are not interested Dave Peterson wrote: Well, once we got rid of that awful MSWord stuff, it was pretty much clear sailing. <vbg jsd219 wrote: works perfect, i can't thank you enough. :-) God bless jsd219 Dave Peterson wrote: Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = Selection.Cells(1).Value If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = Selection.Cells(Selection.Cells.Count).Value If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: Question: i have run into a snag, i found some discrepancies with my spreadsheet and need to adjust your script to accomodate the discrepancies. instead of an input box asking me what text string to start and end with, i need the sStart and sEnd to base things off my selection and use the first row in my selection as the sStart and the last row in my selection as the sEnd God bless jsd219 Dave Peterson wrote: leaving (A:M, and N:IV alone) should have asked: leaving A:M, and O:IV alone) Dave Peterson wrote: So what happens with the cells/rows with "Vocabulario en acción 1" on them? Do you delete the entire row or do you just delete that single cell and shift everything up (leaving (A:M, and N:IV alone)? I left some code at the bottom that you can change. But the way it is now, it deletes the entire row. Try this against a copy of your worksheet--just in case. Option Explicit Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String Dim wks As Worksheet Dim RngToDelete As Range Dim myStr As String Dim bReplace As Boolean Set wks = ActiveSheet With wks Set myRng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") If Trim(sStart) = "" Then MsgBox "quitting!" Exit Sub End If sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") If Trim(sEnd) = "" Then MsgBox "Quitting" Exit Sub End If bReplace = False For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then bReplace = True myStr = myCell.Offset(1, 0).Value If RngToDelete Is Nothing Then Set RngToDelete = myCell.Offset(1, 0) Else Set RngToDelete = Union(myCell.Offset(1, 0), RngToDelete) End If ElseIf LCase(myCell.Value) Like LCase(sEnd & "*") Then bReplace = False Else If bReplace = True Then myCell.Value = myStr & " - " & myCell.Value End If End If Next myCell If RngToDelete Is Nothing Then 'do nothing Else 'delete the entire row RngToDelete.EntireRow.Delete 'or just that cell in Column N 'RngToDelete.Delete Shift:=xlUp End If End Sub jsd219 wrote: :-) here is an example of what i am trying to do: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 Communication 1.2 Students understand and interpret... Comparisons 4.1 Students demonstrate understanding... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 Communication 1.1 Students engage in conversations... Communication 1.2 Students understand and interpret... Communication 1.3 Students present information... Cultures 2.1 Students demonstrate an understanding... Comparisons 4.2 Students demonstrate understanding... CORE INSTRUCTION Notice the difference with the two days. what i need to do is find the cell in column "N" with the text string "STANDARDS FOR FOREIGN LANGUAGE LEARNING" select the cell directly below this one and paste its contents in front of all cells below in the same column intil i reach the cell with "CORE INSTRUCTION" The two days above would then look like this: DAY 1 STANDARDS FOR FOREIGN LANGUAGE LEARNINGCORE INSTRUCTION Vocabulario en acción 1 - Communication 1.2 Students understand... Vocabulario en acción 1 - Comparisons 4.1 Students demonstrate... CORE INSTRUCTION DAY 2 STANDARDS FOR FOREIGN LANGUAGE LEARNING Vocabulario en acción 1 - Communication 1.1 Students engage... Vocabulario en acción 1 - Communication 1.2 Students... Vocabulario en acción 1 - Communication 1.3 Students present... Vocabulario en acción 1 - Cultures 2.1 Students demonstrate an... Vocabulario en acción 1 - Comparisons 4.2 Students demonstrat... CORE INSTRUCTION i have 10,000 rows of this info that i need to go through and make these changes to: what i love about Shauna's script is it allows me to put in whatever text i want as a starting point and whatever text i want as an ending point giving me freedon to make adjustments if needed down the line. her script works perfect if i had everything in word. i have everything in excel and there is no way i could move it to word, there are too many formulas and scripts populating this spread sheet. i pulled up the REF in the tools tab and selected Word which helped but i still get the activedocument error. i tried several attempts to change that line but i could not figure out what it needs to be to make this run in excel. any help would be very much appreciated and thanks for all of the help so far. God bless jsd219 Dave Peterson wrote: Excel doesn't have an activedocument. Are you trying to automate changes to a word document from excel or are you trying to change values in an excel file? If you're changing an excel file, make sure you select the range to adjust before you run either of the macros. If that doesn't work, you may want to describe what you want in plain old words. jsd219 wrote: Unfortunately neither one of those worked. the original script works perfectly in word but my work is in excel. i am having problems with the code below: Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range God bless jsd219 Dave Peterson wrote: Typo... Dim myCell as range In fact, a few typos! Option Explicit Sub AddTextToCellsExcel() Dim myCell As Range Dim myRng As Range Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells myCell.Value = myCell.Value & "CORE Instruction" Next myCell End Sub 'or.... Sub AddTextToCellsExcel2() Dim myCell As Range Dim myRng As Range Dim sStart As String Dim sEnd As String sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set myRng = Selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") For Each myCell In myRng.Cells If LCase(myCell.Value) Like LCase(sStart & "*") Then myCell.Value = myCell.Value & sEnd End If Next myCell End Sub jsd219 wrote: Both of them are giving me Compile error: User-defined type not defined and then it highlights Dim myCell As ranges God bless jsd219 Dave Peterson wrote: Maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells mycell.value = mycell.value & "CORE Instruction" next mycell sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") End Sub === Or maybe... Option Explicit Sub AddTextToCellsExcel() Dim myCell as ranges dim myRng as range dim sStart as string dim sEnd as string sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") set myrng = selection 'or give it the range you need 'set myrng = worksheets("sheet9999").range("a1:c12") for each mycell in myrng.cells if lcase(mycell.value) like lcase(sstart & "*") then mycell.value mycell.value & sEnd next mycell End Sub jsd219 wrote: Shauna Kelly wrote me a wonderful script but unfortunaltey she wrote it in Word and i need it in Excel. can anyone help me convert this script from Word to Excel? Below is the script: Option Explicit Sub AddTextToCells() Dim sStart As String Dim sCopy As String Dim sEnd As String Dim oTable As Word.Table Dim oRow As Word.Row Dim rngCell As Word.Range Dim rngCopy As Word.Range Dim bReplace As Boolean sStart = InputBox(Prompt:="Text to search for", _ Default:="STANDARDS FOR FOREIGN LANGUAGE LEARNING") sEnd = InputBox(Prompt:="Text to end with", _ Default:="CORE INSTRUCTION") Set oTable = ActiveDocument.Tables(1) For Each oRow In oTable.Rows 'Get the range of the cell Set rngCell = oRow.Cells(1).Range 'Omit the end of cell marker rngCell.End = rngCell.End - 1 'Process the cell If rngCell.Text = sStart Then bReplace = True 'Get the replacement text Set rngCopy = oRow.Next.Cells(1).Range rngCopy.End = rngCopy.End - 1 sCopy = rngCopy.Text 'Delete the row following our row oRow.Next.Delete ElseIf rngCell.Text = sEnd Then bReplace = False ElseIf bReplace Then rngCell.InsertBefore sCopy & " - " End If Next oRow End Sub Thanks in advance God bles jsd219 -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson -- Dave Peterson |
#27
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Sometimes, you can loop through a specified range and plop the values into
cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped |
#28
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
My bad i posted the wrong function.
One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped |
#29
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
VBA has sample code when you look under .find.
Option Explicit Sub testme01() Dim myRng As Range Dim FoundCell As Range Dim WhatToFind As String Dim FirstAddress As String WhatToFind = "asdf" With Worksheets("sheet1") Set myRng = .Range("a:a") 'say End With With myRng Set FoundCell = .Cells.Find(What:=WhatToFind, _ After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If FoundCell Is Nothing Then MsgBox "not found in: " & myRng.Address(0, 0) Else FirstAddress = FoundCell.Address Do 'do your stuff that does all the work 'and put it into the adjacent(?) cell FoundCell.Offset(0, 1).Value = "whatever you need here" 'look for more Set FoundCell = .FindNext(FoundCell) If FoundCell Is Nothing Then Exit Do ElseIf FoundCell.Address = FirstAddress Then Exit Do End If Loop End If End With End Sub jsd219 wrote: My bad i posted the wrong function. One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped -- Dave Peterson |
#30
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank you :-)
Actually i started piecing things together and came up with this but i am at a loss. instead of moving myword to the cell in the next column i want myword to say where it is and everything else in that cell to move over to the cell in the next column. i am going crazy trying to figure this out. Sub FindMoveColor() Dim rng As Range Dim cell As Range Dim start_str As Integer myword = InputBox("Enter the search string ") Mylen = Len(myword) With Worksheets(InputBox("Enter the Worksheet")) Set rng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) cell.Offset(0, 0).Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next End Sub God bless jsd219 Dave Peterson wrote: VBA has sample code when you look under .find. Option Explicit Sub testme01() Dim myRng As Range Dim FoundCell As Range Dim WhatToFind As String Dim FirstAddress As String WhatToFind = "asdf" With Worksheets("sheet1") Set myRng = .Range("a:a") 'say End With With myRng Set FoundCell = .Cells.Find(What:=WhatToFind, _ After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If FoundCell Is Nothing Then MsgBox "not found in: " & myRng.Address(0, 0) Else FirstAddress = FoundCell.Address Do 'do your stuff that does all the work 'and put it into the adjacent(?) cell FoundCell.Offset(0, 1).Value = "whatever you need here" 'look for more Set FoundCell = .FindNext(FoundCell) If FoundCell Is Nothing Then Exit Do ElseIf FoundCell.Address = FirstAddress Then Exit Do End If Loop End If End With End Sub jsd219 wrote: My bad i posted the wrong function. One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped -- Dave Peterson |
#31
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I don't understand what you mean by "myword to stay where it is".
You typed it into an inputbox. Maybe.... For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) 'put original string in adjacent cell cell.offset(0,1).value = cell.value 'leave just that word in column N cell.Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next === ..offset(0,1) means to "go" to the right one column. ..offset(0,0) isn't required. It means that there is no "movement". jsd219 wrote: Thank you :-) Actually i started piecing things together and came up with this but i am at a loss. instead of moving myword to the cell in the next column i want myword to say where it is and everything else in that cell to move over to the cell in the next column. i am going crazy trying to figure this out. Sub FindMoveColor() Dim rng As Range Dim cell As Range Dim start_str As Integer myword = InputBox("Enter the search string ") Mylen = Len(myword) With Worksheets(InputBox("Enter the Worksheet")) Set rng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) cell.Offset(0, 0).Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next End Sub God bless jsd219 Dave Peterson wrote: VBA has sample code when you look under .find. Option Explicit Sub testme01() Dim myRng As Range Dim FoundCell As Range Dim WhatToFind As String Dim FirstAddress As String WhatToFind = "asdf" With Worksheets("sheet1") Set myRng = .Range("a:a") 'say End With With myRng Set FoundCell = .Cells.Find(What:=WhatToFind, _ After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If FoundCell Is Nothing Then MsgBox "not found in: " & myRng.Address(0, 0) Else FirstAddress = FoundCell.Address Do 'do your stuff that does all the work 'and put it into the adjacent(?) cell FoundCell.Offset(0, 1).Value = "whatever you need here" 'look for more Set FoundCell = .FindNext(FoundCell) If FoundCell Is Nothing Then Exit Do ElseIf FoundCell.Address = FirstAddress Then Exit Do End If Loop End If End With End Sub jsd219 wrote: My bad i posted the wrong function. One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped -- Dave Peterson -- Dave Peterson |
#32
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks, :-)
you can't imagine how much this is helping me. i can't thank you enough. What i use the "myword" for is to find the proper cells in the spread sheet the "myword" is the constant within the sheet. Soooo, you up for one more? if not i fully understand and again thank you for all of your help. if it is any consolation i am learning a tone from your scripts hopefully i will be able to write my own soon. God bless jsd219 Dave Peterson wrote: I don't understand what you mean by "myword to stay where it is". You typed it into an inputbox. Maybe.... For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) 'put original string in adjacent cell cell.offset(0,1).value = cell.value 'leave just that word in column N cell.Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next === .offset(0,1) means to "go" to the right one column. .offset(0,0) isn't required. It means that there is no "movement". jsd219 wrote: Thank you :-) Actually i started piecing things together and came up with this but i am at a loss. instead of moving myword to the cell in the next column i want myword to say where it is and everything else in that cell to move over to the cell in the next column. i am going crazy trying to figure this out. Sub FindMoveColor() Dim rng As Range Dim cell As Range Dim start_str As Integer myword = InputBox("Enter the search string ") Mylen = Len(myword) With Worksheets(InputBox("Enter the Worksheet")) Set rng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) cell.Offset(0, 0).Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next End Sub God bless jsd219 Dave Peterson wrote: VBA has sample code when you look under .find. Option Explicit Sub testme01() Dim myRng As Range Dim FoundCell As Range Dim WhatToFind As String Dim FirstAddress As String WhatToFind = "asdf" With Worksheets("sheet1") Set myRng = .Range("a:a") 'say End With With myRng Set FoundCell = .Cells.Find(What:=WhatToFind, _ After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If FoundCell Is Nothing Then MsgBox "not found in: " & myRng.Address(0, 0) Else FirstAddress = FoundCell.Address Do 'do your stuff that does all the work 'and put it into the adjacent(?) cell FoundCell.Offset(0, 1).Value = "whatever you need here" 'look for more Set FoundCell = .FindNext(FoundCell) If FoundCell Is Nothing Then Exit Do ElseIf FoundCell.Address = FirstAddress Then Exit Do End If Loop End If End With End Sub jsd219 wrote: My bad i posted the wrong function. One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped -- Dave Peterson -- Dave Peterson |
#33
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I see you got more responses to your other post, too. (Where you gave more
info.) Personally, I'd start a new thread. Lots of people may be skipping this one. jsd219 wrote: Thanks, :-) you can't imagine how much this is helping me. i can't thank you enough. What i use the "myword" for is to find the proper cells in the spread sheet the "myword" is the constant within the sheet. Soooo, you up for one more? if not i fully understand and again thank you for all of your help. if it is any consolation i am learning a tone from your scripts hopefully i will be able to write my own soon. God bless jsd219 Dave Peterson wrote: I don't understand what you mean by "myword to stay where it is". You typed it into an inputbox. Maybe.... For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) 'put original string in adjacent cell cell.offset(0,1).value = cell.value 'leave just that word in column N cell.Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next === .offset(0,1) means to "go" to the right one column. .offset(0,0) isn't required. It means that there is no "movement". jsd219 wrote: Thank you :-) Actually i started piecing things together and came up with this but i am at a loss. instead of moving myword to the cell in the next column i want myword to say where it is and everything else in that cell to move over to the cell in the next column. i am going crazy trying to figure this out. Sub FindMoveColor() Dim rng As Range Dim cell As Range Dim start_str As Integer myword = InputBox("Enter the search string ") Mylen = Len(myword) With Worksheets(InputBox("Enter the Worksheet")) Set rng = .Range("N1", .Cells(.Rows.Count, "N").End(xlUp)) End With For Each cell In rng start_str = InStr(cell.Value, myword) If start_str Then cell.EntireRow.Interior.Color = RGB(204, 255, 204) cell.Offset(0, 0).Value = myword ' cell.Characters(start_str, Mylen).Delete End If Next End Sub God bless jsd219 Dave Peterson wrote: VBA has sample code when you look under .find. Option Explicit Sub testme01() Dim myRng As Range Dim FoundCell As Range Dim WhatToFind As String Dim FirstAddress As String WhatToFind = "asdf" With Worksheets("sheet1") Set myRng = .Range("a:a") 'say End With With myRng Set FoundCell = .Cells.Find(What:=WhatToFind, _ After:=.Cells(.Cells.Count), LookIn:=xlFormulas, _ LookAt:=xlPart, SearchOrder:=xlByRows, _ SearchDirection:=xlNext, MatchCase:=False) If FoundCell Is Nothing Then MsgBox "not found in: " & myRng.Address(0, 0) Else FirstAddress = FoundCell.Address Do 'do your stuff that does all the work 'and put it into the adjacent(?) cell FoundCell.Offset(0, 1).Value = "whatever you need here" 'look for more Set FoundCell = .FindNext(FoundCell) If FoundCell Is Nothing Then Exit Do ElseIf FoundCell.Address = FirstAddress Then Exit Do End If Loop End If End With End Sub jsd219 wrote: My bad i posted the wrong function. One of my bigest issues is something as simple as: find cells within a specified column that contain specified text. once these cells are found i need to pull the specified text out of the cell and paste it in another cell one column to the right, then color the entire row. i have found several functions and put together several formulas to do this but i sure would love to be able to run a macro that does this for me. i have tones of rows i have to go through. God bless jsd219 Dave Peterson wrote: Sometimes, you can loop through a specified range and plop the values into cells: Sub testme() Dim myCell As Range Dim myRng As Range With Worksheets("sheet1") Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp)) End With For Each myCell In myRng.Cells myCell.Offset(0, 1).Value = ExtractDuration(myCell.Value) Next myCell End Sub Heck, you may want to just add a formula to the cell that does the work: =extractduration(a1) You could have a macro apply that formula to a specific range, calculate, and convert to values: Dim myRng as range set myrng = activesheet.range("a1:a10") with myrng.offset(0,1) .formular1c1 = "=extractduration(rc[-1])" .value = .value end with There were parts missing from those functions, so I didnt' test any of this. jsd219 wrote: No prob, i have been reading the newsgroups and have figured out how to open the pdf from excel, now i am working with sendkeys to see if i can select all, copy, then paste. if i am successful i will let you know. :-) Is there an easy way to turn the 2 functions below into a script that will place the results in a specified column? Public Function ExtractDuration(InputString As String) As String Dim astrWords() As String Dim intWordToCheck As Integer Dim strWordtoCheck As String Dim astrTemp() As String Dim intCounter As Integer intCounter = 0 astrWords = Split(InputString, " ", -1, vbTextCompare) intWordToCheck = UBound(astrWords) strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Do Until NumbercommaNumber(strWordtoCheck) = False ReDim Preserve astrTemp(intCounter) astrTemp(intCounter) = strWordtoCheck intCounter = intCounter + 1 intWordToCheck = intWordToCheck - 1 strWordtoCheck = astrWords(intWordToCheck) strWordtoCheck = EliminateCommas(strWordtoCheck) Loop ExtractDuration = Join(astrTemp, vbLf) End Function Private Function NumbercommaNumber(InputString As String) As Boolean Dim intPositionOfPeriod As Integer Dim strLeftPart As String Dim strRightPart As String intPositionOfPeriod = InStr(1, InputString, "(", vbTextCompare) Select Case intPositionOfPeriod Case 1 NumbercommaNumber = False Case Else ' there is a period in there strLeftPart = Strings.Left(InputString, intPositionOfPeriod + 1) ' strRightPart = Strings.Mid(InputString, intPositionOfPeriod - 1) If IsNumeric(strLeftPart) = True Then ' And IsNumeric(strRightPart) = True Then NumbercommaNumber = True Else NumbercommaNumber = False End If End Select End Function <<snipped -- Dave Peterson -- Dave Peterson -- Dave Peterson |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel Macro call Word Macro with Parameters | Excel Programming | |||
Need syntax for RUNning a Word macro with an argument, called from an Excel macro | Excel Programming | |||
WORD-DELIMITED string vba macro for excel/word | Excel Programming | |||
passing arguments from an excel macro to a word macro | Excel Discussion (Misc queries) | |||
Macro - Open Word with Excel macro | Excel Discussion (Misc queries) |