Here's the refactored and fixed version:
Sub TWB_Copy_columns()
'TWB_Copy_columns Macro
'Range("B14").Select
'Selection.End(xlToRight).Select
'celltxt = Selection.Text
' Use explicit references and avoid select. In this case, you will need to
' qualify the workbook and sheetname of the range you are using. We can then
' directly access the value of that range.
' Also, no need to declare a string just to hold onto the value. Directly use the value instead
With ThisWorkbook.Sheets("Sheetname")
If InStr(1, .Range("B14").End(xlToRight).value, "-") > 0 Or InStr(1, .Range("B14").End(xlToRight).value, "/") > 0 Then
.Range("BD5:BB36").value = .Range("BA5:BB36").value
End If
End With
End Sub
First, always avoid Select
and Activate
. In this case, I directly assign the values instead of trying to copy, paste, or select. Any time you see Range("A5").Select; Selection.Value
you really need Range("A5").Value
. Likewise, never have an unqualified range. Range("A5")
is the same as saying ActiveSheet.Range("A5")
which can complicate things if the wrong sheet is active.
Finally, if you are literally using a variable for one comparison, use the direct value. There's no need to create a variable for just one task (at least in my opinion).
Edit:
As Ralph suggests, consider reading this thread: How to avoid using Select in Excel VBA macros. Once you learn to avoid Select
your abilities will skyrocket.