Assigning a cell using variables VBA

LRoy

New Member
Joined
Aug 5, 2022
Messages
8
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I'm currently learning the basics of VBA so I'm aware the solution to this is probably quite obvious.

1659690620062.png


With the above, I'm expecting to see the value for the variable z placed into the cell which has been determined by the user.
The code runs through fine without any errors, however the value for z is not being placed into the designated cell.
If I remove the variables x and y for Range, and just type a normal cell reference e.g. ("A1") then it works perfectly.
I'm aware that the error lies somewhere within the Range("x" & y) = z but I can't figure it out.
Any help would be appreciated.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try this:

Range(x & y ) = z

Or

Cells(y, x) = z
The first solution solved it thank you! I thought because it was string it would have to be in the quotation marks.
 
Upvote 0

Forum statistics

Threads
1,214,952
Messages
6,122,454
Members
449,083
Latest member
Ava19

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