Hi -
So the other day I received help through the Forum to create a macro. The macro works perfectly when it is stored in the workbook. What I want to do now is store this macro in my Personal.xlsb. So I first copied the macro, I then removed it completely from my active workbook and, three... pasted it in my Personal.xlsb module. However, when I run the macro from my Personal.xlsb I get a 'Variable not defined' error for Sheet1???
Why is this happening?
Public Sub NormaliseData()
Dim cel As Range
Dim intCol As Integer
Dim i As Long, j As Long
Dim wksR As Worksheet, wksN As Worksheet
Set wksR = Sheet1
Set wksN = Sheet2
i = wksR.Range("C" & Rows.Count).End(xlUp).Row
For Each cel In wksR.Range("C2:C" & i).Cells
For intCol = 10 To 16 'cols J->P.
If wksR.Cells(cel.Row, intCol).Value <> "" Then
'session exists - create normalised record:
j = wksN.Range("A" & Rows.Count).End(xlUp).Row + 1
wksN.Range("A" & j).Value = wksR.Range("C" & cel.Row).Value 'last name.
wksN.Range("B" & j).Value = wksR.Range("B" & cel.Row).Value 'first name.
wksN.Range("C" & j).Value = wksR.Range("G" & cel.Row).Value 'ph. no.
wksN.Range("D" & j).Value = wksR.Range("H" & cel.Row).Value 'email.
wksN.Range("E" & j).Value = wksR.Cells(cel.Row, intCol).Value 'session info.
End If
Next intCol
Next cel
Set cel = Nothing: Set wksR = Nothing: Set wksN = Nothing
End Sub
Bookmarks