VBA Next Alphabet Char based on previous selected cell

Winterfest

New Member
Joined
Mar 13, 2019
Messages
2
Hello!

I have tried to do this using a formula, but sometimes the rows are separated by a few blank.

How would i go about having a macro only work with the selected range of cells, look at the row above and add 1 to the CHAR. Thats what i am finding really tricky to figure out.
If i need to be more clear, I will be:
I select cells A2, A3, A5, A8, A9 etc.

No real order to when there are blanks between the rows, which i s why i was wondering if i can get it to only work with the selected ones. I can do this manually, shouldn't be a problem.
Otherwise, i was going to see if i could build in something that would avoid Selection.SpecialCells(xlCellTypeBlanks).

Any advice would be appreciated
 

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.
Am no VBA expert so Im looking at a formula solution.

Example data, expected output?
 
Upvote 0
Hey Special-K99,

This is for a instruction sheet, where column A is lettered steps (a,b,c,d,e...) during editing, i sometimes remove steps of move them around, and was looking for a way to quickly redo the lettering.
I have attempted to use =CHAR(CODE(A1)+1), but haven't gotten the results i wanted, due to sometimes having steps that use 2-4 rows, and only the first row of that step has the letter.
Can't attach a workbook to give you a great example, but i can try to make a table here to show you
[TABLE="class: outer_border, width: 500, align: center"]
<tbody>[TR]
[TD]1[/TD]
[TD]Step 1 Things we are making[/TD]
[/TR]
[TR]
[TD]a[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]b[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]c[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]d[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]e[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Your VBA expertise seems better than mine, think I'll have to leave this to someone else to solve.
Doubt a formula would work looking at selection of cells
 
Upvote 0
Hey Winterfest,

Try the below code ... Is this what you need ? If yes, do you have more than 26 steps ?

Code:
Sub ReOrder()


Dim Col As String, Cnt As Long, fRow As Long, lRow As Long


Col = InputBox("Please enter the Column letter where you would like to Re-Order your data")
fRow = InputBox("Please enter the number of first row of your alphabets")
lRow = ActiveSheet.Range(Col & Rows.Count).End(xlUp).Row


Cnt = 65 ' change this to 97 in case you want lower case letters
For x = fRow To lRow
    If Cells(x, Col).Value <> "" Then
        Cells(x, Col).Value = Chr(Cnt)
        Cnt = Cnt + 1
    End If
Next
    
End Sub
 
Upvote 0
How about
Code:
Sub Winterfest()
   Dim i As Long
   Dim Cl As Range
   
   i = 65
   For Each Cl In Range("A:A").SpecialCells(xlConstants)
      If Not IsNumeric(Cl) Then
         Cl.Value = Chr(i)
         i = i + 1
      Else
         i = 65
      End If
   Next Cl
End Sub
This will reset the letters to A whenever there is a number in col A.
And as mse330 said, will you ever go above Z
 
Upvote 0
Formula:

[Table="width:, class:grid"][tr][td="bgcolor:#C0C0C0"][/td][td="bgcolor:#C0C0C0"]
A​
[/td][td="bgcolor:#C0C0C0"]
B​
[/td][td="bgcolor:#C0C0C0"]
C​
[/td][td="bgcolor:#C0C0C0"]
D​
[/td][/tr][tr][td="bgcolor:#C0C0C0"]
1​
[/td][td]1[/td][td]Step 1[/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
2​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
3​
[/td][td="bgcolor:#CCFFCC"]
a​
[/td][td][/td][td][/td][td="bgcolor:#CCFFCC"]A3: =IF(MATCH(999, A$1:A2) > IFERROR(MATCH("z", A$1:A2), 0), "a", CHAR(CODE(INDEX(A$1:A2, MATCH("z", A$1:A2) + 1))))[/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
4​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
5​
[/td][td="bgcolor:#CCFFCC"]
b​
[/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
6​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
7​
[/td][td="bgcolor:#CCFFCC"]
c​
[/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
8​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
9​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
10​
[/td][td]2[/td][td]Step 2[/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
11​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
12​
[/td][td="bgcolor:#CCFFCC"]
a​
[/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
13​
[/td][td][/td][td][/td][td][/td][td][/td][/tr]
[tr][td="bgcolor:#C0C0C0"]
14​
[/td][td="bgcolor:#CCFFCC"]
b​
[/td][td][/td][td][/td][td][/td][/tr]
[/table]


Copy the formula in the first cell to each cell where needed.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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