derrickjp7
New Member
- Joined
- Jan 30, 2020
- Messages
- 16
- Office Version
- 2019
- Platform
- 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!
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