Row and Column from a Cell Input

helpexcel

Well-known Member
Joined
Oct 21, 2009
Messages
656
Hi - I have a spreadsheet where the user put in the starting cell of data that's to be used. So they would put "G7" in cell B2. I'm trying to get code that will split that G7 into row and column. I was using the code below that had the user enter the row and column separately, but it's much simpler to have them enter both together. Any help is appreciated.

VBA Code:
Dim rng As Range
Dim colFR As Variant
With ws2
     colFR = .Range("B2")
    Set rowFR = .Range("D2")
End With

Dim LastRow As Long
With ws1
    LastRow = .Cells(.Rows.Count, colFR).End(xlUp).Row
    Set rng = .Range(.Cells(rowFRD, colFR), .Cells(LastRow, colFR))
    rng.Copy ws3.Range("A3")
End With
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Hi,

You will a couple of UDFs to Extract Letters and to Extract Numbers

VBA Code:
Option Explicit

Function ExtractLetters(var) As String
Dim i As Long
Dim result As String
    For i = 1 To Len(var)
        If Asc(Mid(UCase(var), i, 1)) >= 65 And Asc(Mid(UCase(var), i, 1)) <= 90 Then
            result = result & Mid(var, i, 1)
        End If
    Next i
    ExtractLetters = result
End Function

Function ExtractNumbers(var) As Double
Dim i As Long
Dim result As String
    For i = 1 To Len(var)
        If Asc(Mid(UCase(var), i, 1)) >= 48 And Asc(Mid(UCase(var), i, 1)) <= 57 Then
            result = result & Mid(var, i, 1)
        End If
    Next i
    ExtractNumbers = result
End Function
 
Upvote 0
Thanks for the response. I see how the top one is getting the column and the other the row. Would you mind explaining how I would then use this in the creating ranges? And which portion of the code I would manipulate if I have multiple cells with an cell address reference?
 
Upvote 0
Whether in your spreadsheet or with a macro, both functions can be used with :
= ExtractLetters(B2) and = ExtractNumbers(B2)
 
Upvote 0
Got it, works great thanks!

Is there an easier way to use this in the range copy code I have?
 
Upvote 0
Hi,
In order to simplify ...
You said the input in cell B2 would be "G7" ...
Could the first letter go beyond Z ... or not ?
 
Upvote 0
There are time that a cell might be blank, so there is nothing to extract. How do I stop this code from erroring out and just move on?
 
Upvote 0
OK ...
Both UDF's do allow to extract all Letters and Numbers
In order to get the Column Number extracted from cell B2 in another cell, you can test folllowing formula :
Code:
 
Upvote 0
yep, It works great. would like to adjust it slightly so that it it doesn't error when trying to extract data from a blank cell.
 
Upvote 0

Forum statistics

Threads
1,215,514
Messages
6,125,263
Members
449,219
Latest member
daynle

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