Macro named argument - Error

aavvijit

Board Regular
Joined
Mar 23, 2009
Messages
75
Hi,

Can some please help me to correct this mcro code - this I am using to fill a range with alphabatical list.

Code:
Sub AlphaFill()
    Dim Cell, CellChars
    Dim Default, Prompt, Title
    Dim rangeSelected As Range
    Dim UpperCase As Boolean
    Title = "AlphaFill Cell Selection"
    Default = Selection.Address
    Prompt = vbCrLf _
      & "Use mouse in conjunction with " _
      & "SHIFT and CTRL keys to" & vbCrLf _
      & "click and drag or type in name(s) " _
      & "of cell(s) to AlphaFill" & vbCrLf & vbCrLf _
      & "Currently selected cell(s): " & Selection.Address
    On Error Resume Next
    Set rangeSelected = InputBox(Prompt, Title, Default, Type:=8)
    If rangeSelected Is Nothing Then Exit Sub
    UpperCase = True
    Randomize
    For Each Cell In rangeSelected
        CellChars = Chr(64 + Int((Rnd * 26) + 1))
        If Not UpperCase Then CellChars = LCase(CellChars)
        Cell.Value = CellChars
    Next
End Sub

Above code is giving error "Named argument error" on following line : "Type:=8"

I am using Excel 2003.

Please help where the code is going wrong.

Regards,
 
And what if the user chooses a range that consists of more than 26 cells?
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Then it should start repeating the sequence once again.

Like (AA, AB, AC, AD .............. & so on)

Hope I am clear to explain.

Thanks,
 
Upvote 0
No, that is not clear, as the sample you have shown is NOT a repeat of the original sequence. Can you explain what you want?
 
Upvote 0
you better take the instance upto 26 alphabet now, we will restrict the user to use upto 26 only.

if need arise we look beyound that in future.
 
Upvote 0
This does what you want ( and you'll see that it's almost identical to your first macro ... I can't understand how you couldn't do this yourself, to be honest ):
Code:
Sub AlphaFill()
    Dim Cell, CellChars
    Dim Default, Prompt, Title
    Dim rangeSelected As Range
    Dim UpperCase As Boolean
    Title = "AlphaFill Cell Selection"
    Default = Selection.Address
    Prompt = vbCrLf _
      & "Use mouse in conjunction with " _
      & "SHIFT and CTRL keys to" & vbCrLf _
      & "click and drag or type in name(s) " _
      & "of cell(s) to AlphaFill" & vbCrLf & vbCrLf _
      & "Currently selected cell(s): " & Selection.Address
    On Error Resume Next
    Set rangeSelected = Application.InputBox(Prompt, Title, Default, Type:=8)
    If rangeSelected Is Nothing Then Exit Sub
    UpperCase = True
    Randomize
    If rangeSelected.Cells.Count > 26 Then _
        MsgBox "Only first 26 cells with be filled"
    alphapointer = 0
    For Each Cell In rangeSelected
        alphapointer = alphapointer + 1
        If alphapointer > 26 Then Exit For
        CellChars = Chr(64 + alphapointer)
        If Not UpperCase Then CellChars = LCase(CellChars)
        Cell.Value = CellChars
    Next
End Sub
... it displays a message warning the user that only the first 26 cells will be filled, should they select more than 26 cells.
 
Upvote 0
Something like this:-
Code:
Dim rng As Range
Dim iChr As Integer
Dim oCell As Range
 
Set rng = Application.InputBox("Select a range to fill:-", , Selection.Address, , , , , Type:=8)
iChr = 64
For Each oCell In rng
  iChr = iChr + 1
  oCell = Chr(iChr)
Next oCell
 
Upvote 0

Forum statistics

Threads
1,224,550
Messages
6,179,462
Members
452,915
Latest member
hannnahheileen

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