Calling a sub from excel sheet

satish_j

New Member
Joined
Sep 16, 2011
Messages
10
I found a excel sub/macro from Internet that allows a single cell contents to be split into multiple rows based on certain character.I copied the code and pasted in a new module window opened from excel(F11 key)
Now,if i go back to worksheet and enter the name of sub in a cell,it says 'That name is not valid'.I guess iam not properly calling the sub.
Can anyone help me how to call a sub from excel sheet?
Thanks..
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
you cannot call a 'sub" from a worksheet like formula...you can call only functions or formulas...


try replacing the word "sub" with "public function"...
 
Upvote 0
This is the code i got from Net
Code:
Sub x()
    Dim iRow        As Long
    Dim astr()      As String

    Application.ScreenUpdating = False

    For iRow = Cells(Rows.Count, "A").End(xlUp).Row To 1 Step -1
        If InStr(Cells(iRow, "B").Value, ",") Then
            astr = Split(Cells(iRow, "B"), ",")
            Rows(iRow + 1).Resize(UBound(astr)).Insert
            With Rows(iRow).Resize(UBound(astr) + 1)
                .Rows(1).Copy Destination:=.Columns(1)
                .Columns(2).Value = WorksheetFunction.Transpose(astr)
            End With
        End If
    Next iRow

    Application.ScreenUpdating = True
End Sub

I also tried replacing 'sub' with 'function' but it gives a long error on calling from sheet as:
There is a circular rerence in an open work-book.......blah...blah..
Any other ideas?
 
Upvote 0
as per the macro your data that you need to split should be in column B....
have you checked with this ?? other than that the macro is fine
 
Upvote 0
as per the macro your data that you need to split should be in column B....
have you checked with this ?? other than that the macro is fine

i entered data in column B1(abc,123,104) and pressed 'enter',but iam not getting rows with each value..
 
Upvote 0
dude you will need to run the macro in order to get the output...

I don't know how you used to do this earlier but now after pasting the values in B1, go the the code in VBA editor and press F5 or the Run button on the menu bar and your work will be done
 
Upvote 0
FWIW, I would tell us what it is you'd like to do and where (what module) you plunked this into?
 
Upvote 0
dude you will need to run the macro in order to get the output...

I don't know how you used to do this earlier but now after pasting the values in B1, go the the code in VBA editor and press F5 or the Run button on the menu bar and your work will be done

Perfect,it worked gr8..sorry,iam newbie to macros..
can you help me change the character used in Sub from comma(,) to angle bracket(>)
Nevermind,i got it..
 
Last edited:
Upvote 0
over here in the code

Code:
astr = Split(Cells(iRow, "B"), ",")


replace the "," with ">" or any other character as u like....you can even put a word over there
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,908
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top