Why are my variables not being recognized?

SBF12345

Well-known Member
Joined
Jul 26, 2014
Messages
614
Greetings,

I have a relatively simple script.

I assign a variant variable using worksheet inputs like:

Code:
b = ActiveWorkbook.Worksheets("WorksheetName").Range("B10").Value

Later in the script I attempt to use the value of b:

Code:
Selection.Offset(0,1).Value = b

When I check the related sheets I am receiving no value, as if the contents of B10 was empty.

What could be happening here?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Apologies,

Because I was using Offset multiple times the initial .select from which values were being offset was causing the error. problem solved
 
Upvote 0
Perhaps you are looking at the wrong sheet, or your selection is not what you think it is. Any reference to Selection is to the active sheet at the point where it's made. Have you verified that b is not a zero-length string or empty at the point where the line you posted is executed?
 
Upvote 0
The code was similar to:

Code:
Range("A1").Select
Selection.Value = y
Selection.Offset(0,1).Value = b
Selection.Offset(0,1).Value = c

It was writing over the b value, referencing the selected range, not the recent ranges to which values were assigned.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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