I'm having two problems with an Excel 2010 macro. I run the macro once a month, each time on a new set of data that contains a varying number of rows. It is supposed to remove a reference number from one cell in each row. (All of these cells are in the same column.) Unfortunately, rather than working only on the cells having data, it works on a fixed range, which usually means it tries to "fix" many blank cells in that column, which means I have to clean out a lot of #VALUE! error messages after the macro runs. I want the macro to only work on the cells in that column that have data, no matter how many or how few rows there are.
Second, the reference number the macro is set up to remove is either 8 or 9 digits long, with a # sign before it and parentheses on either side: (#12345678) or (#123456789). There is text in front of this number that I need to keep. The macro works fine for removing the 9-digit numbers but leaves the space that separates the last letter of the text from the opening parenthesis of the 8-digit numbers. Leaving those spaces means I have to do additional work to clean them out later, which I'd like to avoid.
Here's the current code:
Sub Remove_Module_Numbers()
'
' Remove_Module_Numbers Macro
' This macro removes the Brainshark-assigned 9-digit module numbers.
'
'
Range("B1").Select
Selection.EntireColumn.Insert
Range("A1").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Range("B2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=MID(C[-1],1,FIND("" ("",C[-1],1)-1)"
Range("B2").Select
Selection.AutoFill Destination:=Range("b2:b379")
Range(Selection, Selection.End(xlDown)).Select
Range("B2").Select
' Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2").Select
Application.CutCopyMode = False
Range("B2").Select
Selection.EntireColumn.Delete
End Sub
I'm sure the fixes are relatively straight-forward but my VBA coding skills are limited and I haven't been able to figure out what to do. Any help would be greatly appreciated.
Second, the reference number the macro is set up to remove is either 8 or 9 digits long, with a # sign before it and parentheses on either side: (#12345678) or (#123456789). There is text in front of this number that I need to keep. The macro works fine for removing the 9-digit numbers but leaves the space that separates the last letter of the text from the opening parenthesis of the 8-digit numbers. Leaving those spaces means I have to do additional work to clean them out later, which I'd like to avoid.
Here's the current code:
Sub Remove_Module_Numbers()
'
' Remove_Module_Numbers Macro
' This macro removes the Brainshark-assigned 9-digit module numbers.
'
'
Range("B1").Select
Selection.EntireColumn.Insert
Range("A1").Select
Selection.Copy
Range("B1").Select
ActiveSheet.Paste
Range("B2").Select
Application.CutCopyMode = False
ActiveCell.FormulaR1C1 = "=MID(C[-1],1,FIND("" ("",C[-1],1)-1)"
Range("B2").Select
Selection.AutoFill Destination:=Range("b2:b379")
Range(Selection, Selection.End(xlDown)).Select
Range("B2").Select
' Range("B2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Range("A2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A2").Select
Application.CutCopyMode = False
Range("B2").Select
Selection.EntireColumn.Delete
End Sub
I'm sure the fixes are relatively straight-forward but my VBA coding skills are limited and I haven't been able to figure out what to do. Any help would be greatly appreciated.