Incrementing a Character Variable

derrickjp7

New Member
Joined
Jan 30, 2020
Messages
16
Office Version
  1. 2019
Platform
  1. Windows
Hello!

What I'm trying to achieve:

I want to search my Named Ranges, my Named Ranges are the Slot references.
First I search for "Slot1," if it exists, take whats in "Slot1" and place it in "Slot1A" and in "Slot1B"
Next, search for "Slot2," if it exists, take whats in "Slot2" and place it in "Slot2A" and in "Slot2B"
So on and so forth until I get to a Named Range (ie: maybe "Slot9") that doesn't exist

I'm using "s" as my integer variable to increase the slot number. But I'm having a hard time figuring out a way to increment the variable "Letter" from A to B. To be honest, I'm not real sure if my overall code will work for what I'm trying to do. Any help would be appreciated! Thanks!

VBA Code:
Sub Macro7()
Dim nm As Name
Dim s As Integer
Dim Letter As Variant
s = 1

For Each nm In ThisWorkbook.Names
Letter = A
If nm.Name = "Slot" & s Then
     Range("CADImport!Slot" & s & Letter)(1, 1).Value = ThisWorkbook.Names("Slot1").RefersToRange(2, 2).Value
     Letter = Chr(Asc(Letter) + 1)
     Range("CADImport!Slot" & s & Letter)(1, 1).Value = ThisWorkbook.Names("Slot1").RefersToRange(2, 2).Value
     s = s + 1
Else
End If
Next
End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
The Asc Code for the Capital A = 65, B = 66, C = 67 etc
Use the Asc Codes.
Or
Use the CustomListContents.
If you Alphabet, capitals, is the third list, this will get you the A
Application.GetCustomListContents(3)(1)
Obviously, a 2 in place of the 1 will get you the B etc etc
 
Upvote 0

Forum statistics

Threads
1,214,787
Messages
6,121,565
Members
449,038
Latest member
Guest1337

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