PDA

View Full Version : [SOLVED:] Need help constructing VBA code to enter selected letter into cell after data already



estatefinds
07-12-2016, 03:20 PM
I have data that is in the worksheet in columns K:R and rows 1 to 70.

so I need a macro in which I select the data say for Example: K2:to Q2 by using mouse to select this area.

then hit Alt F8 then a small box appears in which I enter any letter from the following letters A through P.

for this example I would type the upper case letter A.

then press enter,
and it would be entered into the selected area in the cell undistrurbng the data currently in the cell but just adding the -A.

Thank you in advance!!!

Paul_Hossler
07-12-2016, 04:28 PM
Not much in the way of error checking, but something like this maybe



Option Explicit
Sub AddSuffixLetter()
Dim rCell As Range
Dim sSuffix As String

If Not TypeOf Selection Is Range Then Exit Sub

sSuffix = UCase(Application.InputBox("Enter A - P", "Adding Suffix"))
If sSuffix = "FALSE" Then Exit Sub
sSuffix = Left(sSuffix, 1)
If Not sSuffix Like "[A-P]" Then Exit Sub
For Each rCell In Selection.Cells
rCell.Value = rCell.Value & sSuffix
Next
End Sub

estatefinds
07-12-2016, 05:31 PM
Great Job!!!! Thank you very much!!!!! You do Great Work!!!!

snb
07-13-2016, 12:22 AM
or


Sub M_snb()
c00 = UCase(InputBox("Character"))
If c00 Like "[A-Z]" Then Selection = Evaluate(Selection.Address & "&""-" & c00 & """")
End Sub