Hi all,
I'm sure there is a quick and easy to solution to this but your help would be very appreciated.
I have created a code then runs off a button in excel. Basically what it does is you click the button it opens a form which pulls in the data from the cell above where the button is, allows you to edit the cell above, removes the little square character then pops it back into the cell above. All works fine.
I want to use this code in numerous places so is there is way of getting the VB to work out what the cell above is.
In this example, the button is in B13, and the cell I want to edit is B12.
Rather than writing the code out loads of times, is there a quick way, of just doing one code which works it out?
My code is here:
[VBA]
Private Sub cmdAdd_Click()
Dim sData As String
Dim lRowNum As Long
'pulls in data currently in cell to the text box on the form
sData = txtData.Text
Sheets("sheet1").Range("B12").Value = sData
' removes square character
Dim MyChar
MyChar = Chr(13)
Sheets("sheet1").Columns("B:C").Replace _
What:=MyChar, Replacement:=" ", _
SearchOrder:=xlByColumns, MatchCase:=True
End Sub
Private Sub UserForm_Initialize()
UserForm1.txtData.Text = Sheets("sheet1").Range("B12").Value
End Sub
[/VBA]
Thanks for your time.