Need help making a simple modification to my code.

pglufkin

Board Regular
Joined
Jun 19, 2005
Messages
127
I have the following code which merely defines a range based on it finding a special character in a cell of text relative to where my beginning cursor is. It does this for another procedure. It works fine:

Sub rangeset()
Dim N As Long, NN As Long
Dim M As Long, col As Long
Dim reg As Range, s As String
Application.Calculation = xlCalculationManual
col = ActiveCell.Column
N = Cells(Rows.Count, col).End(xlUp).Row
M = ActiveCell.Row
For NN = M To N
s = Cells(NN, col).Value
If Asc(Right(s, 1)) = 63 Then
Set reg = Range(Cells(M, Selection.Column), Cells(NN, Selection.Column))
Exit For
End If
Next NN
Call Test_ConcatAndColorParts
End Sub

Problem is, I am trying to call this procedure while my cursor is on another worksheet and the code to do that I have come up with so far is:

Sub rangeset()
Dim N As Long, NN As Long
Dim M As Long, col As Long
Dim reg As Range, s As String
Dim shSource As Worksheet
Set shSource = ThisWorkbook.Sheets("DataSet")
col = shSource.Columns(9)
N = Cells(Rows.Count, col).End(xlUp).Row
M = shSource.Rows("3")
For NN = M To N
s = Cells(NN, col).Value
If Asc(Right(s, 1)) = 63 Then
Set reg = shSource.Range(Cells(M, 9), Cells(NN, 9))
Exit For
End If
Next NN
Call Test_ConcatAndColorParts
End Sub

It doesn't like col = shSource.Columns(9) and I am missing something here I'm not quite sure what is. Thank you for your help.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Forum statistics

Threads
1,214,583
Messages
6,120,378
Members
448,955
Latest member
BatCoder

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