Define Range with Variant

mlanthier

New Member
Joined
Dec 8, 2011
Messages
21
I'm trying to insert value ex. Canada in a column to be defined by the user (prompt) and based on cell content, column also defined by the user.

Here's my try:
Dim FinalRow As Long
Dim n As Long
Dim ColumnOU As Variant
Dim ClassifResult As Variant




'Table definition
FinalRow = Cells(Rows.Count, 1).End(xlUp).Row
ColunmOU = InputBox("Type OU column number")
ClassifResult = InputBox("Type column where yu want the countries inserted")


'Section A - Canada


For n = 2 To FinalRow
If Cells(n, ColumnOU) Like "*CANADA*" Then
Cells(n, ClassifResult) = "Canada"
End If
Next n

The macro works well if I use numbers ex. Cells(n, 5) instead of the Variant
I guess I cannot use the Variant in the range or maybe the Variant must be defined as an integer first.

thanks for your help,
Martin
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
You've got typos in the code.
If you put
Code:
Option Explicit
at the very top of each module (before any code) it will help you to spot them.
 
Upvote 0

Forum statistics

Threads
1,223,889
Messages
6,175,226
Members
452,620
Latest member
dsubash

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